Python: More precise regex parsing

This commit is contained in:
Rasmus Lerchedahl Petersen
2021-06-28 14:45:41 +02:00
parent e5f07cc4d3
commit 74ca1d00b9
5 changed files with 201 additions and 66 deletions

View File

@@ -1,32 +1,32 @@
import re
re.compile(r'[]-[]') #$ MISSING: charRange=1:2-3:4
re.compile(r'[---]') #$ MISSING: charRange=1:2-3:4
re.compile(r'[\---]') #$ MISSING: charRange=1:3-4:5
re.compile(r'[--\-]') #$ MISSING: charRange=1:2-3:5
re.compile(r'[\--\-]') #$ cMISSING: harRange=1:3-4:6
re.compile(r'[0-9-A-Z]') #$ MISSING: charRange=1:2-3:4 charRange=5:6-7:8
re.compile(r'[0\-9-A-Z]') #$ MISSING: charRange=4:5-6:7
re.compile(r'[0--9-A-Z]') #$ MISSING: charRange=1:2-3:4 charRange=4:5-6:7
re.compile(r'[]-[]') #$ charRange=1:2-3:4
re.compile(r'[---]') #$ charRange=1:2-3:4
re.compile(r'[\---]') #$ charRange=1:3-4:5
re.compile(r'[--\-]') #$ charRange=1:2-3:5
re.compile(r'[\--\-]') #$ charRange=1:3-4:6
re.compile(r'[0-9-A-Z]') #$ charRange=1:2-3:4 charRange=5:6-7:8
re.compile(r'[0\-9-A-Z]') #$ charRange=4:5-6:7
re.compile(r'[0--9-A-Z]') #$ charRange=1:2-3:4 charRange=4:5-6:7
re.compile(r'[^A-Z]') #$ MISSING: charRange=2:3-4:5
re.compile(r'[^A-Z]') #$ charRange=2:3-4:5
re.compile(r'[\0-\09]') #$ MISSING: charRange=1:3-4:7
re.compile(r'[\0-\09]') #$ charRange=1:3-4:7
re.compile(r'[\0123-5]') #$ MISSING: charRange=5:6-7:8
re.compile(r'[\0123-5]') #$ charRange=5:6-7:8
#Negative lookahead
re.compile(r'(?!not-this)^[A-Z_]+$') #$ MISSING: charRange=14:15-16:17
re.compile(r'(?!not-this)^[A-Z_]+$') #$ charRange=14:15-16:17
#Negative lookbehind
re.compile(r'^[A-Z_]+$(?<!not-this)') #$ MISSING: charRange=2:3-4:5
re.compile(r'^[A-Z_]+$(?<!not-this)') #$ charRange=2:3-4:5
#OK -- ODASA-ODASA-3968
re.compile('(?:[^%]|^)?%\((\w*)\)[a-z]') #$ MISSING: charRange=22:23-24:25
re.compile('(?:[^%]|^)?%\((\w*)\)[a-z]') #$ charRange=22:23-24:25
#ODASA-3985
#Half Surrogate pairs
re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]') #$ MISSING: charRange=1:2-3:4 charRange=6:7-8:9
re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]') #$ charRange=1:2-3:4 charRange=6:7-8:9
#Outside BMP
re.compile(u'[\U00010000-\U0010ffff]') #$ MISSING: charRange=1:2-3:4
re.compile(u'[\U00010000-\U0010ffff]') #$ charRange=1:2-3:4

View File

@@ -1,29 +1,29 @@
import re
re.compile(r'\A[+-]?\d+') #$ MISSING: charSet=2:6
re.compile(r'(?P<name>[\w]+)|') #$ MISSING: charSet=9:13
re.compile(r'\|\[\][123]|\{\}') #$ MISSING: charSet=6:11
re.compile(r'[^A-Z]') #$ MISSING: charSet=0:6
re.compile(r'\A[+-]?\d+') #$ charSet=2:6
re.compile(r'(?P<name>[\w]+)|') #$ charSet=9:13
re.compile(r'\|\[\][123]|\{\}') #$ charSet=6:11
re.compile(r'[^A-Z]') #$ charSet=0:6
re.compile("[]]") #$ charSet=0:3
re.compile("[][]") #$ MISSING: charSet=0:4
re.compile("[^][^]") #$ MISSING: charSet=0:6
re.compile("[.][.]") #$ charSet=0:3 MISSING: charSet=3:6
re.compile("[][]") #$ charSet=0:4
re.compile("[^][^]") #$ charSet=0:6
re.compile("[.][.]") #$ charSet=0:3 charSet=3:6
re.compile("[[]]") #$ charSet=0:3
re.compile("[^]]") #$ MISSING: charSet=0:4
re.compile("[^-]") #$ MISSING: charSet=0:4
re.compile("[]-[]") #$ MISSING: charSet=0:5
re.compile("[^]-[]") #$ MISSING: charSet=0:6
re.compile("[^]]") #$ charSet=0:4
re.compile("[^-]") #$ charSet=0:4
re.compile("[]-[]") #$ charSet=0:5
re.compile("[^]-[]") #$ charSet=0:6
re.compile("]]][[[[]") #$ MISSING: charSet=3:8
re.compile("]]][[[[]") #$ charSet=3:8
#ODASA-3985
#Half Surrogate pairs
re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]') #$ MISSING: charSet=0:5 charSet=5:10
re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]') #$ charSet=0:5 charSet=5:10
#Outside BMP
re.compile(u'[\U00010000-\U0010ffff]') #$ MISSING: charSet=0:5
re.compile(u'[\U00010000-\U0010ffff]') #$ charSet=0:5
#Misparsed on LGTM
re.compile(r"\[(?P<txt>[^[]*)\]\((?P<uri>[^)]*)") #$ MISSING: charSet=10:14 charSet=28:32
re.compile(r"\[(?P<txt>[^[]*)\]\((?P<uri>[^)]*)") #$ charSet=10:14 charSet=28:32
# parses wrongly, sees this \|/ as a char set start
re.compile(r'''(?:[\s;,"'<>(){}|[\]@=+*]|:(?![/\\]))+''') #$ MISSING: charSet=3:25 charSet=30:35
re.compile(r'''(?:[\s;,"'<>(){}|[\]@=+*]|:(?![/\\]))+''') #$ charSet=3:25 charSet=30:35

View File

@@ -5,13 +5,13 @@ re.compile(r'''\b''') #$ escapedCharacter=0:2
re.compile(r"\b") #$ escapedCharacter=0:2
re.compile(u"\b") # not escape
re.compile("\b") # not escape
re.compile(r'\\\b') #$ escapedCharacter=0:2 MISSING: escapedCharacter=2:4
re.compile(r'\\\b') #$ escapedCharacter=0:2 escapedCharacter=2:4
re.compile(r'[\---]') #$ escapedCharacter=1:3
re.compile(r'[--\-]') #$ MISSING: escapedCharacter=3:5
re.compile(r'[\--\-]') #$ escapedCharacter=1:3 MISSING: escapedCharacter=4:6
re.compile(r'[0\-9-A-Z]') #$ MISSING: escapedCharacter=2:4
re.compile(r'[\0-\09]') #$ escapedCharacter=1:3 MISSING: escapedCharacter=4:7
re.compile(r'[\0123-5]') #$ MISSING: escapedCharacter=1:5
re.compile(r'[--\-]') #$ escapedCharacter=3:5
re.compile(r'[\--\-]') #$ escapedCharacter=1:3 escapedCharacter=4:6
re.compile(r'[0\-9-A-Z]') #$ escapedCharacter=2:4
re.compile(r'[\0-\09]') #$ escapedCharacter=1:3 escapedCharacter=4:7
re.compile(r'[\0123-5]') #$ escapedCharacter=1:5
#ODASA-3985
#Half Surrogate pairs
@@ -20,4 +20,4 @@ re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]') # not escapes
re.compile(u'[\U00010000-\U0010ffff]') # not escapes
#Misparsed on LGTM
re.compile(r"\[(?P<txt>[^[]*)\]\((?P<uri>[^)]*)") #$ escapedCharacter=0:2 MISSING: escapedCharacter=16:18 escapedCharacter=18:20
re.compile(r"\[(?P<txt>[^[]*)\]\((?P<uri>[^)]*)") #$ escapedCharacter=0:2 escapedCharacter=16:18 escapedCharacter=18:20

View File

@@ -1,4 +1,4 @@
import re
re.compile(r'(?P<first>\w+) (?P<second>\w+)') #$ MISSING: group=0:14 group=15:30
re.compile(r'([)(])') #$ MISSING: group=0:6
re.compile(r'(?P<first>\w+) (?P<second>\w+)') #$ group=0:14 group=15:30
re.compile(r'([)(])') #$ group=0:6