Skip to content

Commit

Permalink
Fix UnicodeEncodeError in zkg create with non-ASCII characters in u…
Browse files Browse the repository at this point in the history
…ser vars
  • Loading branch information
AmazingPP committed Jun 27, 2024
1 parent bdc15fa commit c6d2ef3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions testing/baselines/tests.template-create/output
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
<...>/out3 (installed: master) - TODO: A more detailed description of test3.
error: could not determine value of user variable "name", provide via environment or --user-var
error: the following features are unknown: "doesntexist". Template "foo" offers "readme".
"foo" will use value of "name" (the name of the package, e.g. "FooBar") from command line: 你こ안مγПनสXש😊©GBCDČM
4 changes: 4 additions & 0 deletions testing/tests/template-create
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@
# Request an unknown feature. This should fail.
# @TEST-EXEC-FAIL: zkg create --packagedir out5 --template $TEMPLATES/foo --feature doesntexist >>output 2>&1

# Provide non-ASCII characters variable via --user-var and ensure resulting package installs
# @TEST-EXEC: zkg create --packagedir out6 --template $TEMPLATES/foo --user-var name=你こ안مγПनสXש😊©GBCDČM >>output
# @TEST-EXEC: zkg install ./out6

# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output
4 changes: 2 additions & 2 deletions zeekpkg/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,8 @@ def _replace(self, tmpl, content):
for name, val in tmpl.params().items():
pat = "@" + name + "@"
if not isinstance(content, str):
pat = bytes(pat, "ascii")
val = bytes(val, "ascii")
pat = bytes(pat, "utf-8")
val = bytes(val, "utf-8")
content = re.sub(pat, val, content, flags=re.IGNORECASE)

return content
Expand Down

0 comments on commit c6d2ef3

Please sign in to comment.