Skip to content

fix(binder): add utf-8 encoding to all file open calls - #71

Merged
hastagAB merged 2 commits into
fossology:masterfrom
rishabh23rohil:rishabh23rohil/fix/utf8-encoding-binder
Mar 26, 2026
Merged

hastagAB merged 2 commits into
fossology:masterfrom
rishabh23rohil:rishabh23rohil/fix/utf8-encoding-binder

Conversation

@rishabh23rohil

Copy link
Copy Markdown
Contributor

All four file-reading functions in binder.py use open(file) without specifying encoding. On systems where the default encoding is not utf-8, this causes UnicodeDecodeError when parsing source files with non-ASCII characters like copyright symbols or accented author names. Added encoding=utf-8 to all four open() calls. All 75 existing tests pass. FOSSology v4.6.0.115 running locally via Docker.

Signed-off-by: Rishabh Rohil <rishabhrohil024@gmail.com>

@hastagAB hastagAB left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rishabh23rohil Good fix for the encoding issue, but two things need to be addressed.

  1. Missing error handler: encoding="utf-8" without an error handler will still raise UnicodeDecodeError on files with invalid UTF-8 bytes, which is the exact scenario this PR aims to prevent. Add errors="replace" to all four calls.

  2. Broken regex in extractAssignedString: The look-behind in the regex is variable-width, which causes re.error at runtime. This is out of scope for this PR but worth fixing before merging.

Please address the error handler and this is good to go.

…egex

Address review feedback:
- Add errors="replace" to all four open() calls so files with
  invalid UTF-8 bytes are handled gracefully instead of raising
  UnicodeDecodeError.
- Replace variable-width lookbehind in extractAssignedString regex
  with a simpler capturing-group pattern that avoids re.error at
  runtime.

All 75 existing tests pass.

Signed-off-by: Rishabh Rohil <rishabhrohil024@gmail.com>
@rishabh23rohil
rishabh23rohil force-pushed the rishabh23rohil/fix/utf8-encoding-binder branch 2 times, most recently from 8e5773b to a87540f Compare March 25, 2026 14:32
@rishabh23rohil

Copy link
Copy Markdown
Contributor Author

@hastagAB Thanks for the review! Addressed both points in the latest commit: Added errors="replace" to all four open() calls so invalid UTF-8 bytes are gracefully replaced instead of raising UnicodeDecodeError. Fixed the variable-width lookbehind in extractAssignedString — the \s* inside the lookbehind caused re.error at runtime. Replaced it with a simpler capturing-group pattern that matches the same strings. All 75 existing tests pass. Please let me know if there's anything else!

@rishabh23rohil
rishabh23rohil force-pushed the rishabh23rohil/fix/utf8-encoding-binder branch from a87540f to d03952c Compare March 25, 2026 14:41
@hastagAB
hastagAB merged commit ba36700 into fossology:master Mar 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants