Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/test/common_url_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ BOOST_AUTO_TEST_CASE(decode_malformed_test) {
BOOST_CHECK_EQUAL(UrlDecode(" %Z "), " %Z ");
BOOST_CHECK_EQUAL(UrlDecode(" % X"), " % X");

BOOST_CHECK_EQUAL(UrlDecode("%%ffg"), "%\xffg");
Copy link
Member

@Sjors Sjors Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to scratch my head on this one...

It iterates from left to right, the first thing it finds is %. It then tries if the next two characters are hex, which they are not, so it puts the literal % in the result. Then it moves to the next % which is followed by valid hex ff. Since 0xff is invalid unicode, we have to represent it with the escape sequence "\xff". And then there's the regular character g.

BOOST_CHECK_EQUAL(UrlDecode("%fg"), "%fg");

BOOST_CHECK_EQUAL(UrlDecode("%-1"), "%-1");
BOOST_CHECK_EQUAL(UrlDecode("%1-"), "%1-");
}
Expand Down