Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unicode on RHS in ini scan #143

Merged
merged 2 commits into from
Mar 20, 2019
Merged

Fix unicode on RHS in ini scan #143

merged 2 commits into from
Mar 20, 2019

Conversation

KevinHock
Copy link
Collaborator

@KevinHock KevinHock commented Mar 20, 2019

Changes

  • 馃悰 Handle unicode in ini_file_parser.py

This bug was trigged only when Unicode was on the RHS e.g.

foo=b氓r

&

  • merged in master to get coverage back up to the minimum (98%)

Why this works

To clarify why unicode_literals fixes this, we format things into a string literal when doing re.compile, so this makes sure it's unicode and not bytes.

This bug was trigged only when Unicode was on the RHS e.g.
```
foo=b氓r
```
@KevinHock KevinHock requested a review from calvinli March 20, 2019 22:46
@calvinli
Copy link
Member

To clarify, the problem this fixes is that a Python 2.7 str cannot be .format()-ed with unicode:

>>> x = u'hell贸'
>>> r'foo{}'.format(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 4: ordinal not in range(128)
>>>

The pattern must be unicode in order to do this:

>>> x = u'hell贸'
>>> ur'foo{}'.format(x)
u'foohell\xf3'
>>>

Copy link
Member

@calvinli calvinli left a comment

Choose a reason for hiding this comment

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

馃殺

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.

None yet

2 participants