Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: toml-compatible fingers-crossed handling for failed input data decoding #613

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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