You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Install the pre-commit Python package (e.g., with pipx)
Install the pre-commit hooks:
pre-commit install
Stage both files:
git add .
Run the pre-commit hook:
pre-commit run --all-files
Observe the resulting crash and traceback:
bandit...................................................................Failed
- hook id: bandit
- exit code: 1
[main] INFO profile include tests: None
[main] INFO profile exclude tests: None
[main] INFO cli include tests: None
[main] INFO cli exclude tests: None
[main] INFO running on Python 3.11.3
[node_visitor] WARNING Unable to find qualified name for module: test.py
Traceback (most recent call last):
File "C:\Users\<username>\.cache\pre-commit\repowg97az4b\py_env-python3\Lib\site-packages\bandit\core\manager.py", line 188, in output_results
report_func(
File "C:\Users\<username>\.cache\pre-commit\repowg97az4b\py_env-python3\Lib\site-packages\bandit\formatters\text.py", line 196, in report
wrapped_file.write(result)
File "C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f44f' in position 135: character maps to <undefined>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\<username>\.cache\pre-commit\repowg97az4b\py_env-python3\Scripts\bandit.EXE\__main__.py", line 7, in <module>
File "C:\Users\<username>\.cache\pre-commit\repowg97az4b\py_env-python3\Lib\site-packages\bandit\cli\main.py", line 672, in main
b_mgr.output_results(
File "C:\Users\<username>\.cache\pre-commit\repowg97az4b\py_env-python3\Lib\site-packages\bandit\core\manager.py", line 197, in output_results
raise RuntimeError(
RuntimeError: Unable to output report using 'txt' formatter: 'charmap' codec can't encode character '\U0001f44f' in position 135: character maps to <undefined>
Expected behavior
I expect Bandit to successfully create the report, either by handing unicode encodings, or by removing the problematic unicode characters.
Bandit version
1.7.5 (Default)
Python version
3.11 (Default)
The text was updated successfully, but these errors were encountered:
I am using Windows. I am able to reproduce the issue on Powershell 7 (7.4.1), Command Prompt and Git Bash (TERM = xterm-256color).
Issue is occurring both in 1.7.5 and the latest version (1.7.8).
Describe the bug
When using the pre-commit hook on a file with unicode characters in it, Bandit will crash.
The bug was fixed for CLI in #362 but the issue is still present when using the pre-commit hook.
Reproduction steps
test.py
:.pre-commit-config.yaml
:Install the
pre-commit
Python package (e.g., withpipx
)Install the pre-commit hooks:
git add .
Expected behavior
I expect Bandit to successfully create the report, either by handing unicode encodings, or by removing the problematic unicode characters.
Bandit version
1.7.5 (Default)
Python version
3.11 (Default)
The text was updated successfully, but these errors were encountered: