Skip to content

Commit

Permalink
Add test case which demonstrates #439
Browse files Browse the repository at this point in the history
tools-test: Make codefactor happy with whitespace.
  • Loading branch information
ThisIsFineTM committed Jan 17, 2025
1 parent 768cbe5 commit 46060ab
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test/tools-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -400,7 +426,6 @@ TEST(tools, getLinks)
"abcd href = qwerty src={123} xyz",
""
);

}
#undef EXPECT_LINKS

Expand Down

0 comments on commit 46060ab

Please sign in to comment.