Skip to content

Commit

Permalink
🐞 Add underscore to encodeURIComponent skipped characters (#1105)
Browse files Browse the repository at this point in the history
Co-authored-by: Atarpara <[email protected]>
  • Loading branch information
Vectorized and atarpara authored Oct 3, 2024
1 parent b43371a commit 357d78e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/utils/LibString.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,8 @@ library LibString {
for { let end := add(s, mload(s)) } iszero(eq(s, end)) {} {
s := add(s, 1)
let c := and(mload(s), 0xff)
// If not in `[0-9A-Z-a-z-.!~*'()]`.
if iszero(and(1, shr(c, 0x47fffffe07fffffe03ff678200000000))) {
// If not in `[0-9A-Z-a-z-_.!~*'()]`.
if iszero(and(1, shr(c, 0x47fffffe87fffffe03ff678200000000))) {
mstore8(o, 0x25) // '%'.
mstore8(add(o, 1), mload(and(shr(4, c), 15)))
mstore8(add(o, 2), mload(and(c, 15)))
Expand Down
8 changes: 5 additions & 3 deletions test/LibString.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1103,9 +1103,10 @@ contract LibStringTest is SoladyTest {
_testEncodeURIComponent("", "");
_testEncodeURIComponent("a", "a");
_testEncodeURIComponent("ab", "ab");
string memory encodeURIComponentSkippedCharacters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~*'()";
_testEncodeURIComponent(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789"
encodeURIComponentSkippedCharacters, encodeURIComponentSkippedCharacters
);
// All of these characters are encoded, they are reserved by URI standard
_testEncodeURIComponent(";/?:@&=+$,# ", "%3B%2F%3F%3A%40%26%3D%2B%24%2C%23%20");
Expand Down Expand Up @@ -1145,12 +1146,12 @@ contract LibStringTest is SoladyTest {
unchecked {
for (uint256 i = 0; i < inputLength; i++) {
bytes1 b = input[i];

if (
(b >= 0x30 && b <= 0x39) // 0-9
|| (b >= 0x41 && b <= 0x5a) // A-Z
|| (b >= 0x61 && b <= 0x7a) // a-z
|| b == 0x2D // -
|| b == 0x5F // '_'
|| b == 0x2E // .
|| b == 0x21 // !
|| b == 0x7E // ~
Expand All @@ -1176,6 +1177,7 @@ contract LibStringTest is SoladyTest {
|| (b >= 0x41 && b <= 0x5a) // A-Z
|| (b >= 0x61 && b <= 0x7a) // a-z
|| b == 0x2D // -
|| b == 0x5F // '_'
|| b == 0x2E // .
|| b == 0x21 // !
|| b == 0x7E // ~
Expand Down

0 comments on commit 357d78e

Please sign in to comment.