fix(core): preserve non-ASCII UTF-8 in double-quoted dotenv values (fixes #96) - #99
Open
Srinivasan8888 wants to merge 1 commit into
Open
Srinivasan8888 wants to merge 1 commit into
Srinivasan8888 wants to merge 1 commit into
Conversation
parse_dotenv decoded double-quoted values with
bytes(value, 'utf-8').decode('unicode_escape'), which reinterprets each
UTF-8 byte as a Latin-1 code point and mangles any multi-byte character
("café" -> "café"). The corrupted value was then forwarded into the
benchmark/gate environment via resolve_runtime_env.
Replace the Latin-1 round-trip with an explicit unescape that handles the
common backslash escapes (\n \t \r \\ \" \' \`) and leaves everything
else -- including non-ASCII -- untouched.
Fixes evo-hq#96.
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.
Problem
parse_dotenvdecoded double-quoted values withbytes(value, "utf-8").decode("unicode_escape"), which reinterprets each UTF-8 byte as a Latin-1 code point. Any multi-byte character is mangled:The corrupted value is then forwarded into the benchmark/gate environment via
resolve_runtime_env, so a double-quoted non-ASCII secret (accented text, a non-Latin API token, em-dash, emoji) reaches the benchmark broken.Fix
Replace the Latin-1 round-trip with an explicit unescape (
_unescape_double_quoted) that honors the common backslash escapes (`\n \t \r \ " ' ``) and leaves everything else — including non-ASCII — untouched.Tests
tests/unit/test_parse_dotenv.py(TDD, written failing first):café, Cyrillic, em-dash + emoji)\n \t \" \\)Full
test_runtime_env.py+test_core.py: 23 passed.Fixes #96.