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

Setting a limit smaller than the minimum possible size of a regex raises ValueError instead of more specific error. #6

Open
jodukes opened this issue Aug 4, 2017 · 1 comment

Comments

@jodukes
Copy link

jodukes commented Aug 4, 2017

Steps to reproduce:

>>> from xeger import Xeger
>>> Xeger(limit=1).xeger("a{2}")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/local/ANT/jodukes/.local/lib/python2.7/site-packages/xeger/xeger.py", line 82, in xeger
    result = self._build_string(parsed)
  File "/home/local/ANT/jodukes/.local/lib/python2.7/site-packages/xeger/xeger.py", line 89, in _build_string
    newstr.append(self._handle_state(state))
  File "/home/local/ANT/jodukes/.local/lib/python2.7/site-packages/xeger/xeger.py", line 94, in _handle_state
    return self._cases[str(opcode).lower()](value)
  File "/home/local/ANT/jodukes/.local/lib/python2.7/site-packages/xeger/xeger.py", line 71, in <lambda>
    'max_repeat': lambda x: self._handle_repeat(*x),
  File "/home/local/ANT/jodukes/.local/lib/python2.7/site-packages/xeger/xeger.py", line 113, in _handle_repeat
    times = randint(start_range, end_range)
  File "/usr/lib/python2.7/random.py", line 242, in randint
    return self.randrange(a, b+1)
  File "/usr/lib/python2.7/random.py", line 218, in randrange
    raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width)
ValueError: empty range for randrange() (2,2, 0)

Expected behaviour:

I expect to see a specific warning that lets me know why the input was bad. For example, one could add assert start_range < end_range, "Character limit exceeded during repeat" before randint in Xeger._handle_repeat

@gatopeich
Copy link

This hits me too. The "default" limit should only apply to undefined ranges like .+ or .*.

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

No branches or pull requests

2 participants