Skip to content

Commit 7e084ae

Browse files
authored
Get rid of expected failures in tokenizer tests
#283
1 parent 8dd59ea commit 7e084ae

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Lib/ldap/schema/tokenizer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
r"|" # or
1414
r"([^'$()\s]+)" # string of length >= 1 without '$() or whitespace
1515
r"|" # or
16-
r"('.*?'(?!\w))" # any string or empty string surrounded by single quotes
17-
# except if right quote is succeeded by alphanumeric char
16+
r"('(?:[^'\\]|\\\\|\\.)*?'(?!\w))"
17+
# any string or empty string surrounded by unescaped
18+
# single quotes except if right quote is succeeded by
19+
# alphanumeric char
1820
r"|" # or
1921
r"([^\s]+?)", # residue, all non-whitespace strings
2022
).findall
2123

24+
UNESCAPE_PATTERN = re.compile(r"\\(.)")
25+
2226

2327
def split_tokens(s):
2428
"""
@@ -30,7 +34,7 @@ def split_tokens(s):
3034
if unquoted:
3135
parts.append(unquoted)
3236
elif quoted:
33-
parts.append(quoted[1:-1])
37+
parts.append(UNESCAPE_PATTERN.sub(r'\1', quoted[1:-1]))
3438
elif opar:
3539
parens += 1
3640
parts.append(opar)

Tests/t_ldap_schema_tokenizer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444

4545
# broken schema of Oracle Internet Directory
4646
TESTCASES_BROKEN_OID = (
47-
("BLUBB DI 'BLU B B ER'MUST 'BLAH' ", ['BLUBB', 'DI', 'BLU B B ER', 'MUST', 'BLAH']),
48-
("BLUBBER DI 'BLU'BB ER' DA 'BLAH' ", ["BLUBBER", "DI", "BLU'BB ER", "DA", "BLAH"]),
47+
"BLUBB DI 'BLU B B ER'MUST 'BLAH' ", #['BLUBB', 'DI', 'BLU B B ER', 'MUST', 'BLAH']
48+
"BLUBBER DI 'BLU'BB ER' DA 'BLAH' ", #["BLUBBER", "DI", "BLU'BB ER", "DA", "BLAH"]
4949
)
5050

5151
# for quoted single quotes inside string values
@@ -104,14 +104,12 @@ def test_utf8(self):
104104
"""
105105
self._run_split_tokens_tests(TESTCASES_UTF8)
106106

107-
@unittest.expectedFailure
108107
def test_broken_oid(self):
109108
"""
110109
run test cases specified in constant TESTCASES_BROKEN_OID
111110
"""
112111
self._run_failure_tests(TESTCASES_BROKEN_OID)
113112

114-
@unittest.expectedFailure
115113
def test_escaped_quotes(self):
116114
"""
117115
run test cases specified in constant TESTCASES_ESCAPED_QUOTES

0 commit comments

Comments
 (0)