Fix TypeError in prepare_tag_prefix on non-ASCII tag prefixes (Python 3)#917
Open
Fix TypeError in prepare_tag_prefix on non-ASCII tag prefixes (Python 3)#917
Conversation
In Python 3, iterating over bytes yields int values, not single-byte bytes objects. Calling ord() on an int raises TypeError. The sibling method prepare_tag already handles this correctly by using '% ch' without ord(). Apply the same fix to prepare_tag_prefix.
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.
Summary
prepare_tag_prefixcrashes with aTypeErrorwhen given a tag prefix containing non-ASCII characters (e.g., Unicode) in Python 3.Problem
In Python 3, iterating over
bytesyieldsintvalues, not single-bytebytesobjects. The percent-encoding loop inprepare_tag_prefixcallsord(ch)on these integer values, which raisesTypeError:The sibling method
prepare_tag(just below on line ~607) handles this correctly with% chinstead of% ord(ch).Reproduction
Fix
Drop the redundant
ord()call to match the workingprepare_tagimplementation: