Skip to content

Commit

Permalink
fix: toml-compatible fingers-crossed handling for failed input data d…
Browse files Browse the repository at this point in the history
…ecoding

Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck committed Nov 3, 2023
1 parent 6002e0e commit da796d2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cyclonedx_py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ def _get_input_parser(self) -> BaseParser:
'When using input from Conda JSON, you need to pipe input via STDIN')
elif self._arguments.input_from_pip:
self._arguments.input_source = open(os.path.join(current_directory, 'Pipfile.lock'),
'rt', encoding="UTF-8")
'rt', encoding="UTF-8", errors='replace')
elif self._arguments.input_from_poetry:
self._arguments.input_source = open(os.path.join(current_directory, 'poetry.lock'),
'rt', encoding="UTF-8")
'rt', encoding="UTF-8", errors='replace')
elif self._arguments.input_from_requirements:
self._arguments.input_source = open(os.path.join(current_directory, 'requirements.txt'), 'rb')
else:
Expand All @@ -297,7 +297,7 @@ def _get_input_parser(self) -> BaseParser:
input_data = input_data.decode(input_encoding)
except ValueError:
# last resort: try utf8 and hope for the best
input_data = input_data.decode('utf-8', 'backslashreplace')
input_data = input_data.decode('utf-8', 'replace')
input_data_fh.close()

if self._arguments.input_from_conda_explicit:
Expand Down
2 changes: 1 addition & 1 deletion cyclonedx_py/parser/pipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
debug_message: DebugMessageCallback = quiet
) -> None:
debug_message('open file: {}', pipenv_lock_filename)
with open(pipenv_lock_filename) as plf:
with open(pipenv_lock_filename, encoding="UTF-8", errors='replace') as plf:
super(PipEnvFileParser, self).__init__(
pipenv_contents=plf.read(), use_purl_bom_ref=use_purl_bom_ref,
debug_message=debug_message
Expand Down
2 changes: 1 addition & 1 deletion cyclonedx_py/parser/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(
debug_message: DebugMessageCallback = quiet
) -> None:
debug_message('open file: {}', poetry_lock_filename)
with open(poetry_lock_filename, errors='backslashreplace') as plf:
with open(poetry_lock_filename, encoding="UTF-8", errors='replace') as plf:
super(PoetryFileParser, self).__init__(
poetry_lock_contents=plf.read(), use_purl_bom_ref=use_purl_bom_ref,
debug_message=debug_message
Expand Down

0 comments on commit da796d2

Please sign in to comment.