Skip to content

Commit 8bda05f

Browse files
Merge branch 'development'
Fixed Exception on empty regex
2 parents d6cd3d2 + c7c8360 commit 8bda05f

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

pyregexp/engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def match_group(ast: Union[RE, GroupNode, OrNode], string: str) -> Tuple[bool, i
212212
'''
213213
nonlocal str_i
214214
backtrack_stack = []
215-
curr_node = ast.children[0]
215+
curr_node = ast.children[0] if len(ast.children) > 0 else None
216216
i = 0 # the children i'm iterating, not to confuse with str_i
217217

218218
# the passed ast can't be a Leaf

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
setup(
88
name='pyregexp',
99
packages=['pyregexp'],
10-
version='0.2.1',
10+
version='0.2.2',
1111
license='MIT',
1212
description='Simple regex library',
1313
long_description=long_description,
1414
long_description_content_type='text/markdown',
1515
author='Lorenzo Felletti',
1616
url='https://github.com/lorenzofelletti/pyregex',
17-
download_url='https://github.com/lorenzofelletti/pyregex/archive/v0.2.1.tar.gz',
17+
download_url='https://github.com/lorenzofelletti/pyregex/archive/v0.2.2.tar.gz',
1818
keywords=['regex', 'regexp', 'engine'],
1919
install_requires=[],
2020
classifiers=[

test/test_engine.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,24 @@ def test_ignore_case_casefolding(reng: RegexEngine):
439439
test_str = "acher"
440440
res, _ = reng.match(regex, test_str, ignore_case=2)
441441
assert res == False
442+
443+
444+
def test_empty_regex(reng: RegexEngine):
445+
regex = r""
446+
test_str = "aaaa"
447+
res, _ = reng.match(regex, test_str)
448+
assert res == True
449+
450+
451+
def test_empty_test_str(reng: RegexEngine):
452+
regex = r"a"
453+
test_str = ""
454+
res, _ = reng.match(regex, test_str)
455+
assert res == False
456+
457+
458+
def test_empty_regex_and_test_str(reng: RegexEngine):
459+
regex = r""
460+
test_str = ""
461+
res, _ = reng.match(regex, test_str)
462+
assert res == True

0 commit comments

Comments
 (0)