From 46060abeffd86ed80024a8b46e35f04519fff551 Mon Sep 17 00:00:00 2001 From: ThisIsFineTM <184989147+ThisIsFineTM@users.noreply.github.com> Date: Sun, 12 Jan 2025 23:47:46 -0500 Subject: [PATCH] Add test case which demonstrates #439 tools-test: Make codefactor happy with whitespace. --- test/tools-test.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/tools-test.cpp b/test/tools-test.cpp index 2651bfb4..9254c700 100644 --- a/test/tools-test.cpp +++ b/test/tools-test.cpp @@ -236,6 +236,10 @@ TEST(tools, isOutofBounds) TEST(tools, normalize_link) { + ASSERT_EQ(normalize_link("", ""), ""); + ASSERT_EQ(normalize_link("/", ""), ""); + ASSERT_EQ(normalize_link("", "/"), "/"); + ASSERT_EQ(normalize_link("/a", "/b"), "a"); // not absolute @@ -250,6 +254,28 @@ TEST(tools, normalize_link) // URI-decoding is performed ASSERT_EQ(normalize_link("/%41%62c", "/"), "Abc"); + + // #439: normalized link reading off end of buffer + // small-string-opt sizes, so sanitizers and valgrind don't pick this up + EXPECT_EQ(normalize_link("%", "/"), "/"); + EXPECT_EQ(normalize_link("%1", ""), ""); + + // ../test/tools-test.cpp:260: Failure + // Expected equality of these values: + // normalize_link("%", "/") + // Which is: "/\01bc" + // "/" + // + // ../test/tools-test.cpp:261: Failure + // Expected equality of these values: + // normalize_link("%1", "") + // Which is: "\x1" "1bc" + // "" + + // test outside of small-string-opt + // valgrind will pick up on the error in this one + EXPECT_EQ(normalize_link("qrstuvwxyz%", "/abcdefghijklmnop"), "/abcdefghijklmnop/qrstuvwxyz"); + EXPECT_EQ(normalize_link("qrstuvwxyz%1", "/abcdefghijklmnop"), "/abcdefghijklmnop/qrstuvwxyz"); } TEST(tools, addler32) @@ -400,7 +426,6 @@ TEST(tools, getLinks) "abcd href = qwerty src={123} xyz", "" ); - } #undef EXPECT_LINKS