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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs while using python2 re lib #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

prikevs
Copy link

@prikevs prikevs commented Mar 20, 2018

Firstly, thanks a lot for providing such a handy tool to do ZG <=> Unicode conversions!

While using this library under python2.7, I found a bug related to the re lib of python.

Reproduce:

  • translate ပြင်သစ်ဘာသာကီးဘုတ် from unicode to zg with Rabbit.uni2zg(u"ပြင်သစ်ဘာသာကီးဘုတ်")

Error:

Traceback (most recent call last):
  File "convert.py", line 5, in <module>
    print(Rabbit.uni2zg(u'ပြင်သစ်ဘာသာကီးဘုတ်'))
  File "/usr/local/google/home/jiebu/Documents/rabbit/rabbit.py", line 10, in uni2zg
    text = re.sub(rule["from"], rule["to"], text)
  File "/usr/lib/python2.7/re.py", line 155, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/usr/lib/python2.7/re.py", line 291, in filter
    return sre_parse.expand_template(template, match)
  File "/usr/lib/python2.7/sre_parse.py", line 831, in expand_template
    raise error, "unmatched group"
sre_constants.error: unmatched group

Solution:

This happens because the second group represented with “g<2>” in the replacement string returns a “None” instead of an empty string. That is (seems) the bug.

  • Change all (xxxx)? to (|xxxx) e.g. ([\u1000-\u1021])? -> (|[\u1000-\u1021]) please see the link above for more details.

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.

1 participant