diff options
author | Richard Walters <rwalters@digitalstirling.com> | 2018-07-01 23:36:07 -0700 |
---|---|---|
committer | Richard Walters <rwalters@digitalstirling.com> | 2018-07-01 23:36:07 -0700 |
commit | 432a413f585c834d7ecd69a46443a33af40f79db (patch) | |
tree | e73f714ce722761c7482870a1acbb7dc81ffaa24 | |
parent | 4c662109404c79440a62888ae8babff81ce1b71e (diff) |
Allow HEXDIG to include lower-case 'a'..'f'
-rw-r--r-- | src/PercentEncodedCharacterDecoder.cpp | 16 | ||||
-rw-r--r-- | src/Uri.cpp | 3 | ||||
-rw-r--r-- | test/src/UriTests.cpp | 25 |
3 files changed, 40 insertions, 4 deletions
diff --git a/src/PercentEncodedCharacterDecoder.cpp b/src/PercentEncodedCharacterDecoder.cpp index 890d392..dc7cd58 100644 --- a/src/PercentEncodedCharacterDecoder.cpp +++ b/src/PercentEncodedCharacterDecoder.cpp @@ -21,7 +21,13 @@ namespace { * This is the character set containing just the upper-case * letters 'A' through 'F', used in upper-case hexadecimal. */ - const Uri::CharacterSet HEX('A', 'F'); + const Uri::CharacterSet HEX_UPPER('A', 'F'); + + /** + * This is the character set containing just the lower-case + * letters 'a' through 'f', used in lower-case hexadecimal. + */ + const Uri::CharacterSet HEX_LOWER('a', 'f'); } @@ -58,8 +64,10 @@ namespace Uri { impl_->decodedCharacter <<= 4; if (IsCharacterInSet(c, DIGIT)) { impl_->decodedCharacter += (int)(c - '0'); - } else if (IsCharacterInSet(c, HEX)) { + } else if (IsCharacterInSet(c, HEX_UPPER)) { impl_->decodedCharacter += (int)(c - 'A') + 10; + } else if (IsCharacterInSet(c, HEX_LOWER)) { + impl_->decodedCharacter += (int)(c - 'a') + 10; } else { return false; } @@ -70,8 +78,10 @@ namespace Uri { impl_->decodedCharacter <<= 4; if (IsCharacterInSet(c, DIGIT)) { impl_->decodedCharacter += (int)(c - '0'); - } else if (IsCharacterInSet(c, HEX)) { + } else if (IsCharacterInSet(c, HEX_UPPER)) { impl_->decodedCharacter += (int)(c - 'A') + 10; + } else if (IsCharacterInSet(c, HEX_LOWER)) { + impl_->decodedCharacter += (int)(c - 'a') + 10; } else { return false; } diff --git a/src/Uri.cpp b/src/Uri.cpp index 3bb3a59..b30796c 100644 --- a/src/Uri.cpp +++ b/src/Uri.cpp @@ -38,7 +38,8 @@ namespace { */ const Uri::CharacterSet HEXDIG{ Uri::CharacterSet('0', '9'), - Uri::CharacterSet('A', 'F') + Uri::CharacterSet('A', 'F'), + Uri::CharacterSet('a', 'f') }; /** diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp index 6d59697..bb541d0 100644 --- a/test/src/UriTests.cpp +++ b/test/src/UriTests.cpp @@ -524,3 +524,28 @@ TEST(UriTests, ParseFromStringFragmentBarelyLegal) { ++index; } } + +TEST(UriTests, ParseFromStringPathsWithPercentEncodedCharacters) { + struct TestVector { + std::string uriString; + std::string pathFirstSegment; + }; + const std::vector< TestVector > testVectors{ + {"%41", "A"}, + {"%4A", "J"}, + {"%4a", "J"}, + {"%bc", "\xbc"}, + {"%Bc", "\xbc"}, + {"%bC", "\xbc"}, + {"%BC", "\xbc"}, + {"%41%42%43", "ABC"}, + {"%41%4A%43%4b", "AJCK"}, + }; + size_t index = 0; + for (const auto& testVector : testVectors) { + Uri::Uri uri; + ASSERT_TRUE(uri.ParseFromString(testVector.uriString)) << index; + ASSERT_EQ(testVector.pathFirstSegment, uri.GetPath()[0]); + ++index; + } +} |