Skip to content

Commit 82a4201

Browse files
committed
Workaround IronPython bug in utils.Matcher
The underlying IronPython bug is this: IronLanguages/ironpython2#515 We started seeing the problem in our acceptance tests when executed on IronPython after taking `fnmatch.translate` into use when robotframework#2471 was implemented. The problem doesn't occur in any of our stable release so no need to create an issue about it.
1 parent e207ad3 commit 82a4201

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/robot/utils/match.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from .compat import py2to3
2121
from .normalizing import normalize
22-
from .platform import PY3
22+
from .platform import IRONPYTHON, PY3
2323
from .robottypes import is_string
2424

2525

@@ -44,6 +44,9 @@ def __init__(self, pattern, ignore=(), caseless=True, spaceless=True,
4444
def _compile(self, pattern, regexp=False):
4545
if not regexp:
4646
pattern = fnmatch.translate(pattern)
47+
# https://github.com/IronLanguages/ironpython2/issues/515
48+
if IRONPYTHON and "\\'" in pattern:
49+
pattern = pattern.replace("\\'", "'")
4750
return re.compile(pattern, re.DOTALL)
4851

4952
def match(self, string):

utest/utils/test_match.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ def test_spaceless(self):
137137
assert Matcher('f*bar').match(text)
138138
assert not Matcher('f*bar', spaceless=False).match(text)
139139

140+
def test_ipy_bug_workaround(self):
141+
# https://github.com/IronLanguages/ironpython2/issues/515
142+
matcher = Matcher("'12345678901234567890'")
143+
assert matcher.match("'12345678901234567890'")
144+
assert not matcher.match("'xxx'")
145+
140146
def _matches(self, string, pattern, **config):
141147
assert Matcher(pattern, **config).match(string), pattern
142148

0 commit comments

Comments
 (0)