Repository navigation
gh-159071: Correct UnicodeDecodeError offsets in utf-8-sig codec when input starts with BOM - #159081
Open
devpryan7792 wants to merge 1 commit into
Open
devpryan7792 wants to merge 1 commit into
devpryan7792 wants to merge 1 commit into
Conversation
…c when input starts with BOM Signed-off-by: Pradyumn jha <devpryan7792@users.noreply.github.com>
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.
When the input starts with a UTF-8 BOM (
codecs.BOM_UTF8),encodings.utf_8_sigwas slicing the input (input = input[3:]) before callingcodecs.utf_8_decode. As a result, any raisedUnicodeDecodeErrorreported offsets and object attributes relative to the sliced input without the BOM (i.e.startwas off by 3, andobjectomitted the initial BOM).This aligns
utf-8-sigwith other BOM-stripping codecs (utf-16andutf-32), which preserve the BOM in the exception'sobject,start, andendattributes:decode(),IncrementalDecoder._buffer_decode(), andStreamReader.decode()inLib/encodings/utf_8_sig.pyto pass the original input tocodecs.utf_8_decodeand strip the leading\ufefffrom the decoded output.test_decode_error_offsets_with_bomtoUTF8SigTestinLib/test/test_codecs.py.Fixes #159071.