Skip to content

Commit

Permalink
Fix missing raw string for '[^\r\n]' (#76)
Browse files Browse the repository at this point in the history
 * Fix missing raw string for '[^\r\n]'
 * fixed test for dot_wildcard
  • Loading branch information
RS-Credentive authored Aug 14, 2024
1 parent 4a16680 commit 2d146af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion elementpath/regex/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def parse_character_class() -> CharacterClass:
while pos < pattern_len:
ch = pattern[pos]
if ch == '.':
regex.append(ch if dot_all else '[^\r\n]')
regex.append(ch if dot_all else r'[^\r\n]')
elif ch in ('^', '$'):
if not anchors:
regex.append(r'\%s' % ch)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def test_issue_079(self):

def test_dot_wildcard(self):
regex = translate_pattern('.+', anchors=False)
self.assertEqual(regex, '^([^\r\n]+)$(?!\\n\\Z)')
self.assertEqual(regex, '^([^\\r\\n]+)$(?!\\n\\Z)')
pattern = re.compile(regex)
self.assertIsNone(pattern.search('line1\rline2\r'))
self.assertIsNone(pattern.search('line1\nline2'))
Expand All @@ -635,7 +635,7 @@ def test_dot_wildcard(self):
self.assertEqual(pattern.search('abc').group(0), 'abc')

regex = translate_pattern('.+T.+(Z|[+-].+)', anchors=False)
self.assertEqual(regex, '^([^\r\n]+T[^\r\n]+(Z|[\\+\\-][^\r\n]+))$(?!\\n\\Z)')
self.assertEqual(regex, '^([^\\r\\n]+T[^\\r\\n]+(Z|[\\+\\-][^\\r\\n]+))$(?!\\n\\Z)')
pattern = re.compile(regex)
self.assertEqual(pattern.search('12T0A3+36').group(0), '12T0A3+36')
self.assertEqual(pattern.search('12T0A3Z').group(0), '12T0A3Z')
Expand Down Expand Up @@ -903,7 +903,7 @@ def test_anchors(self):

def test_lazy_quantifiers(self):
regex = translate_pattern('.*?')
self.assertEqual(regex, '[^\r\n]*?')
self.assertEqual(regex, '[^\\r\\n]*?')
regex = translate_pattern('[a-z]{2,3}?')
self.assertEqual(regex, '[a-z]{2,3}?')
regex = translate_pattern('[a-z]*?')
Expand Down

0 comments on commit 2d146af

Please sign in to comment.