Repository navigation
Conversation
Files were opened without an explicit encoding, so on Windows the default ANSI code page (often cp1252) was used. Valid UTF-8 files containing bytes that are undefined in that code page, such as 0x81, raised UnicodeDecodeError and were silently treated as binary, so any secrets in them were missed. Open files as UTF-8, which is what detect-secrets already assumes elsewhere (README/setup.py), and log skipped files at debug level instead of dropping them without a trace. Adds a regression test that simulates a cp1252 default and verifies a UTF-8 file is still scanned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1013.
_get_lines_from_fileopened files without anencoding, so Python used the platform locale. On Windows that is usually the ANSI code page (cp1252), which cannot decode valid UTF-8 containing bytes such as0x81— the second byte of Cyrillicс, for example. TheUnicodeDecodeErrorwas caught by the existing binary-file handler and the whole file was dropped, so any secrets in it were silently missed.This opens files as UTF-8, which is already what the rest of the project assumes (
README.mdandsetup.pyboth read UTF-8 explicitly). Files that genuinely are not UTF-8 still fall through to the same handler; they now also get a debug line so a skipped file is at least visible with--log-level DEBUG.The regression test simulates a cp1252 default by wrapping
builtins.openand scans a UTF-8 file with a Basic Auth URL. It fails on master with an empty result and passes with the change.Verification:
pytest tests/core/scan_test.py— 8 passedflake8 --max-line-length 100 detect_secrets/core/scan.py tests/core/scan_test.py— cleanunidiff/pytestin untouched tests), unrelated to this change