package-manager
package-manager copied to clipboard
`zkg create` fails with UnicodeEncodeError when using non-ASCII characters in user vars
Description:
When attempting to create a package using zkg create
, I encountered an issue where non-ASCII characters in the user variables (e.g., author name) result in a UnicodeEncodeError
. This prevents the package creation from completing successfully
Steps to Reproduce:
- Run the following command:
zkg create --feature license --packagedir foo
- Provide the following inputs when prompted:
name: Foo
author: 张三 <[email protected]>
license: mit
Observed Output:
2024-06-27 17:36:44 ERROR problem during template instantiation: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Traceback (most recent call last):
File "/opt/homebrew/Cellar/zeek/6.2.1/bin/zkg", line 2295, in cmd_create
package.do_instantiate(tmpl, args.packagedir, args.force)
File "/opt/homebrew/Cellar/zeek/6.2.1/lib/zeek/python/zeekpkg/template.py", line 708, in do_instantiate
super().do_instantiate(tmpl, packagedir, use_force)
File "/opt/homebrew/Cellar/zeek/6.2.1/lib/zeek/python/zeekpkg/template.py", line 552, in do_instantiate
self.instantiate(tmpl)
File "/opt/homebrew/Cellar/zeek/6.2.1/lib/zeek/python/zeekpkg/template.py", line 566, in instantiate
for orig_file, path_name, file_name, content in self._walk(tmpl):
File "/opt/homebrew/Cellar/zeek/6.2.1/lib/zeek/python/zeekpkg/template.py", line 670, in _walk
out_content = self._replace(tmpl, hdl.read())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/zeek/6.2.1/lib/zeek/python/zeekpkg/template.py", line 692, in _replace
val = bytes(val, "ascii")
^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
error: problem during template instantiation: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Expected Output:
The package should be created successfully, handling non-ASCII characters in the user inputs without errors.
Environment:
- zkg version: 3.0.1
- Zeek version: 6.2.1
- Python version: 3.12.4
- OS: macOS (using homebrew)
Additional Information:
The issue seems to stem from an attempt to encode non-ASCII characters using the ASCII codec, resulting in a UnicodeEncodeError
.
Please consider updating the relevant code to handle non-ASCII characters.