Skip to content

Commit

Permalink
fixed index out of bound when regex is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzofelletti committed Mar 24, 2022
1 parent 4f1c01d commit c7c8360
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyregexp/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def match_group(ast: Union[RE, GroupNode, OrNode], string: str) -> Tuple[bool, i
'''
nonlocal str_i
backtrack_stack = []
curr_node = ast.children[0]
curr_node = ast.children[0] if len(ast.children) > 0 else None
i = 0 # the children i'm iterating, not to confuse with str_i

# the passed ast can't be a Leaf
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
setup(
name='pyregexp',
packages=['pyregexp'],
version='0.2.1',
version='0.2.2',
license='MIT',
description='Simple regex library',
long_description=long_description,
long_description_content_type='text/markdown',
author='Lorenzo Felletti',
url='https://github.com/lorenzofelletti/pyregex',
download_url='https://github.com/lorenzofelletti/pyregex/archive/v0.2.1.tar.gz',
download_url='https://github.com/lorenzofelletti/pyregex/archive/v0.2.2.tar.gz',
keywords=['regex', 'regexp', 'engine'],
install_requires=[],
classifiers=[
Expand Down
21 changes: 21 additions & 0 deletions test/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,24 @@ def test_ignore_case_casefolding(reng: RegexEngine):
test_str = "acher"
res, _ = reng.match(regex, test_str, ignore_case=2)
assert res == False


def test_empty_regex(reng: RegexEngine):
regex = r""
test_str = "aaaa"
res, _ = reng.match(regex, test_str)
assert res == True


def test_empty_test_str(reng: RegexEngine):
regex = r"a"
test_str = ""
res, _ = reng.match(regex, test_str)
assert res == False


def test_empty_regex_and_test_str(reng: RegexEngine):
regex = r""
test_str = ""
res, _ = reng.match(regex, test_str)
assert res == True

0 comments on commit c7c8360

Please sign in to comment.