Repository navigation
Conversation
Escaping a UTF-16 string returned those bytes tagged as UTF-16, and unescaping a UTF-16 percent string left the percent signs in place.
Percent-encoding a UTF-16 or UTF-32 string and then tagging the result with that encoding made the escapes unreadable. The result is now US-ASCII, and unescaping reads the percent sequences as characters.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #89.
escapeandescape_uri_componentpercent-encode the raw bytes and then force the source encoding onto the result. For UTF-16LE,\\uFEFFbecomes the bytes of%FF%FEbut the string is tagged UTF-16LE, so it reads as three unrelated characters.unescapeandunescape_uri_componentthen scan those bytes, and each ASCII character occupies two bytes, so%41is never recognized.The escaped result is now US-ASCII when the source encoding is not ASCII-compatible. Unescaping transcodes such a string to UTF-8 before looking for percent sequences. ASCII-compatible strings, including UTF-8, keep the encoding they had.
Before the change,
CGI.escape_uri_component(\"\\uFEFF\".encode(Encoding::UTF_16LE))was a UTF-16LE string (\"\\u4625\\u2546\\u4546\"), and unescaping\"%41\".encode(Encoding::UTF_16LE)returned that same wide string. After it, the escape is the US-ASCII string%FF%FE, and unescaping the wide%41returns\"A\".ruby -Ilib:test/lib -rhelper test/cgi/test_cgi_escape.rb: 443 tests, 538 assertions, 0 failures.