Skip to content

fix(core): preserve non-ASCII UTF-8 in double-quoted dotenv values (fixes #96) - #99

Open
Srinivasan8888 wants to merge 1 commit into
evo-hq:mainfrom
Srinivasan8888:fix/issue-96-dotenv-unicode
Open

Srinivasan8888 wants to merge 1 commit into
evo-hq:mainfrom
Srinivasan8888:fix/issue-96-dotenv-unicode

Conversation

@Srinivasan8888

Copy link
Copy Markdown

Problem

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. Any multi-byte character is mangled:

parse_dotenv('X="café"')['X']  ->  'café'   # wrong
parse_dotenv('Y=café')['Y']    ->  'café'    # unquoted branch is fine

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):

  • double-quoted non-ASCII preserved (café, Cyrillic, em-dash + emoji)
  • unquoted non-ASCII preserved
  • common escapes still work (\n \t \" \\)
  • escapes + unicode combined
  • single-quoted stays literal

Full test_runtime_env.py + test_core.py: 23 passed.

Fixes #96.

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse_dotenv corrupts non-ASCII UTF-8 in double-quoted values (mojibake)

1 participant