Whole file
jawah/charset_normalizer
The author described this change as “fix: return 0.0 multi_byte_usage for empty payloads (#774)”. It counts as a record because the check below fails on the code as it stood at 667b93c92 and passes on 017c75c26, with nothing else changed between the two runs.
Projectjawah/charset_normalizer
Fix saved2026-07-19
Sharing licenceMIT · LICENSE
Change size+5 −1
What the code was meant to do, written into the code itself as a save note
fix: return 0.0 multi_byte_usage for empty payloads (#774)
The change
| 72 | 72 | ||
| 73 | 73 | @property | |
| 74 | 74 | def multi_byte_usage(self) -> float: | |
| 75 | - | return 1.0 - (len(str(self)) / len(self.raw)) | |
| 75 | + | # Empty payloads are valid (from_bytes(b"") returns a match); avoid /0. | |
| 76 | + | raw_len = len(self.raw) | |
| 77 | + | if raw_len == 0: | |
| 78 | + | return 0.0 | |
| 79 | + | return 1.0 - (len(str(self)) / raw_len) | |
| 76 | 80 | ||
| 77 | 81 | def __str__(self) -> str: | |
| 78 | 82 | # Lazy Str Loading |
The check that tells the two apart
fail→pass·tests/test_base_detection.py::test_empty
Check file tests/test_base_detection.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it667b93c9243cc650354562b871fcfcc35282fe97
Broken version dated2026-07-19
Modulecharset_normalizer.models
Units changedCharsetMatch
Fingerprinta4612e210d0ab546
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in jawah/charset_normalizer
- 2026-07-19fix: make CharsetMatch.__eq__ total for non-alias strings (#773)
- 2026-07-07fix: unicodedecodeerror in fallback path
- 2025-08-09:bug: automatically fallback on valid UTF-16 or UTF-32 even if the md says it's noisy
- 2024-12-24:bug: output(...) replace declarative mark using non iana compliant encoding name