Repository navigation
Conversation
cUnescape treated "\x" followed by a non-hex character as an escape with no digits and appended a NUL byte: "a\xg" became "a\0g" in both strict and non-strict mode. The documented grammar is \x[0-9a-fA-F]+, and "\x" at the end of the input already throws "incomplete hex escape sequence" in strict mode and is kept as "\x" in non-strict mode. Handle "\x" followed by any non-hex character the same way as "\x" at the end of the input.
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.
Summary
folly::cUnescapeturned\xfollowed by a character that is not a hex digit into a NUL byte.cUnescape("a\\xg")returned"a\0g"in both strict and non-strict mode. The documented form is\x[0-9a-fA-F]+. Strict mode is documented to throw on an unrecognized sequence, and non-strict mode to leave it unchanged. That is already what happens when\xis the last thing in the input ("incomplete hex escape sequence").The
\xbranch now treats "next character is not a hex digit" like "end of input":a\xga\0gincomplete hex escape sequencea\0ga\xga\xa\xa\x(unchanged)a\x41aAaA(unchanged)aAaA(unchanged)Strict callers that relied on the old NUL byte now get the documented exception.
Fixes #2744
Validation
TEST(Escape, cUnescape)infolly/test/StringTest.cpp. They fail onmain@ 4a2f75a ("it throws nothing";"hello\0g","\0\n") and pass with this change.string_test(all 77 tests) passes. It was built with the CMake build (-DBUILD_TESTS=ON, RelWithDebInfo) and GCC 13.3 on x86_64 Linux.string_testtarget only, not a fullctestrun. Clang and MSVC were not tried.clang-format(folly's.clang-format) reports no changes.main@ 7014db8. Neither touched file changed upstream between the two commits, so the tests were not re-run after the rebase.This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.