Skip to content

Fix Unicode in double-quoted env values - #149

Open
codeofwxz wants to merge 1 commit into
mattrobenolt:mainfrom
codeofwxz:fix/preserve-unicode-in-env-values
Open

codeofwxz wants to merge 1 commit into
mattrobenolt:mainfrom
codeofwxz:fix/preserve-unicode-in-env-values

Conversation

@codeofwxz

Copy link
Copy Markdown

Double-quoted env values containing literal Unicode are corrupted by encoding them as UTF-8 and then decoding those bytes with unicode-escape. For example, NAME="café\n中文 😀" renders mojibake instead of the original characters and a newline.

Protect unpaired backslashes directly before literal non-ASCII characters, then encode Unicode as ASCII character escapes and decode the whole value with the existing codec once. Single-quoted and unquoted values remain unchanged. A single codec call preserves error precedence even when Unicode separates an unknown escape from a malformed one and warnings are treated as errors.

Added 26 test cases covering accents, CJK, emoji, combining characters, escapes, adjacent backslashes, controls, mixed-Unicode error precedence, and rendering a real template with synthetic env data.

Validation: 79 pytest tests passed on Windows with Python 3.9.13 and 3.14.4; Ruff check/format passed; ty passed targeting Linux, as used by CI. Native Windows ty reports a pre-existing nt._supports_virtual_terminal typing error. The Bats suite could not start under local Git Bash because its source-file symlink creation failed; it is not claimed as passing.

The Linux ty target is a static type-check setting, not a Linux runtime test. All 42 Bats tests remained unstarted. Hosted CI and the full supported Python matrix have not been verified. This fixes a separate decoding defect and does not implement the environment-import feature discussed in #142.

Copilot AI lite review requested due to automatic review settings September 12, 2026 13:09

Copilot AI 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.

🟢 Approval recommended

No unresolved blocking issues were identified.

Pull request overview

Fixes Unicode corruption in double-quoted environment values while preserving escape handling.

Changes:

  • Protects backslashes before literal Unicode.
  • Decodes Unicode through a single ASCII-escape pass.
  • Adds comprehensive parser and CLI regression tests.
File summaries
File Summary
tests/test_env_unicode.py Adds Unicode, escape, error-precedence, and CLI coverage.
jinja2cli/cli.py Updates double-quoted environment value decoding.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
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.

2 participants