mirror of https://github.com/progval/irctest.git
Make re.match actually check the whole string matches the pattern (#261)
And explicitly allow trailing space in RPL_WHOISCHANNELS
This commit is contained in:
parent
473db1cc5b
commit
ea66a8f9a4
|
@ -15,7 +15,7 @@ TAG_ESCAPE = [
|
||||||
unescape_tag_value = MultipleReplacer(dict(map(lambda x: (x[1], x[0]), TAG_ESCAPE)))
|
unescape_tag_value = MultipleReplacer(dict(map(lambda x: (x[1], x[0]), TAG_ESCAPE)))
|
||||||
|
|
||||||
# TODO: validate host
|
# TODO: validate host
|
||||||
tag_key_validator = re.compile(r"\+?(\S+/)?[a-zA-Z0-9-]+")
|
tag_key_validator = re.compile(r"^\+?(\S+/)?[a-zA-Z0-9-]+$")
|
||||||
|
|
||||||
|
|
||||||
def parse_tags(s: str) -> Dict[str, Optional[str]]:
|
def parse_tags(s: str) -> Dict[str, Optional[str]]:
|
||||||
|
|
|
@ -106,15 +106,15 @@ def match_string(got: Optional[str], expected: Union[str, Operator, None]) -> bo
|
||||||
elif isinstance(expected, _AnyStr) and got is not None:
|
elif isinstance(expected, _AnyStr) and got is not None:
|
||||||
return True
|
return True
|
||||||
elif isinstance(expected, StrRe):
|
elif isinstance(expected, StrRe):
|
||||||
if got is None or not re.match(expected.regexp, got):
|
if got is None or not re.match(expected.regexp + "$", got):
|
||||||
return False
|
return False
|
||||||
elif isinstance(expected, OptStrRe):
|
elif isinstance(expected, OptStrRe):
|
||||||
if got is None:
|
if got is None:
|
||||||
return True
|
return True
|
||||||
if not re.match(expected.regexp, got):
|
if not re.match(expected.regexp + "$", got):
|
||||||
return False
|
return False
|
||||||
elif isinstance(expected, NotStrRe):
|
elif isinstance(expected, NotStrRe):
|
||||||
if got is None or re.match(expected.regexp, got):
|
if got is None or re.match(expected.regexp + "$", got):
|
||||||
return False
|
return False
|
||||||
elif isinstance(expected, InsensitiveStr):
|
elif isinstance(expected, InsensitiveStr):
|
||||||
if got is None or got.lower() != expected.string.lower():
|
if got is None or got.lower() != expected.string.lower():
|
||||||
|
|
|
@ -56,7 +56,8 @@ class IsupportTestCase(cases.BaseServerTestCase):
|
||||||
return
|
return
|
||||||
|
|
||||||
m = re.match(
|
m = re.match(
|
||||||
r"\((?P<modes>[a-zA-Z]+)\)(?P<prefixes>\S+)", self.server_support["PREFIX"]
|
r"^\((?P<modes>[a-zA-Z]+)\)(?P<prefixes>\S+)$",
|
||||||
|
self.server_support["PREFIX"],
|
||||||
)
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
m,
|
m,
|
||||||
|
@ -117,5 +118,5 @@ class IsupportTestCase(cases.BaseServerTestCase):
|
||||||
parts = self.server_support["TARGMAX"].split(",")
|
parts = self.server_support["TARGMAX"].split(",")
|
||||||
for part in parts:
|
for part in parts:
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
re.match("[A-Z]+:[0-9]*", part), "Invalid TARGMAX key:value: %r", part
|
re.match("^[A-Z]+:[0-9]*$", part), "Invalid TARGMAX key:value: %r", part
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,7 +11,7 @@ from irctest.patma import ANYSTR, StrRe
|
||||||
|
|
||||||
|
|
||||||
class NamesTestCase(cases.BaseServerTestCase):
|
class NamesTestCase(cases.BaseServerTestCase):
|
||||||
def _testNames(self, symbol):
|
def _testNames(self, symbol: bool, allow_trailing_space: bool):
|
||||||
self.connectClient("nick1")
|
self.connectClient("nick1")
|
||||||
self.sendLine(1, "JOIN #chan")
|
self.sendLine(1, "JOIN #chan")
|
||||||
self.getMessages(1)
|
self.getMessages(1)
|
||||||
|
@ -31,7 +31,10 @@ class NamesTestCase(cases.BaseServerTestCase):
|
||||||
"nick1",
|
"nick1",
|
||||||
*(["="] if symbol else []),
|
*(["="] if symbol else []),
|
||||||
"#chan",
|
"#chan",
|
||||||
StrRe("(nick2 @nick1|@nick1 nick2)"),
|
StrRe(
|
||||||
|
"(nick2 @nick1|@nick1 nick2)"
|
||||||
|
+ (" ?" if allow_trailing_space else "")
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,20 +47,26 @@ class NamesTestCase(cases.BaseServerTestCase):
|
||||||
@cases.mark_specifications("RFC1459", deprecated=True)
|
@cases.mark_specifications("RFC1459", deprecated=True)
|
||||||
def testNames1459(self):
|
def testNames1459(self):
|
||||||
"""
|
"""
|
||||||
https://modern.ircdocs.horse/#names-message
|
|
||||||
https://datatracker.ietf.org/doc/html/rfc1459#section-4.2.5
|
https://datatracker.ietf.org/doc/html/rfc1459#section-4.2.5
|
||||||
https://datatracker.ietf.org/doc/html/rfc2812#section-3.2.5
|
|
||||||
"""
|
"""
|
||||||
self._testNames(symbol=False)
|
self._testNames(symbol=False, allow_trailing_space=True)
|
||||||
|
|
||||||
@cases.mark_specifications("RFC1459", "RFC2812", "Modern")
|
@cases.mark_specifications("RFC2812", "Modern")
|
||||||
def testNames2812(self):
|
def testNames2812(self):
|
||||||
"""
|
"""
|
||||||
https://modern.ircdocs.horse/#names-message
|
|
||||||
https://datatracker.ietf.org/doc/html/rfc1459#section-4.2.5
|
|
||||||
https://datatracker.ietf.org/doc/html/rfc2812#section-3.2.5
|
https://datatracker.ietf.org/doc/html/rfc2812#section-3.2.5
|
||||||
"""
|
"""
|
||||||
self._testNames(symbol=True)
|
self._testNames(symbol=True, allow_trailing_space=True)
|
||||||
|
|
||||||
|
@cases.mark_specifications("Modern")
|
||||||
|
@cases.xfailIfSoftware(
|
||||||
|
["Bahamut", "irc2"], "Bahamut and irc2 send a trailing space in RPL_NAMREPLY"
|
||||||
|
)
|
||||||
|
def testNamesModern(self):
|
||||||
|
"""
|
||||||
|
https://modern.ircdocs.horse/#names-message
|
||||||
|
"""
|
||||||
|
self._testNames(symbol=True, allow_trailing_space=False)
|
||||||
|
|
||||||
def _testNamesMultipleChannels(self, symbol):
|
def _testNamesMultipleChannels(self, symbol):
|
||||||
self.connectClient("nick1")
|
self.connectClient("nick1")
|
||||||
|
|
|
@ -97,7 +97,9 @@ class _WhoisTestMixin(cases.BaseServerTestCase):
|
||||||
params=[
|
params=[
|
||||||
"nick1",
|
"nick1",
|
||||||
"nick2",
|
"nick2",
|
||||||
StrRe("(@#chan1 @#chan2|@#chan2 @#chan1)"),
|
# trailing space was required by the RFCs, and Modern explicitly
|
||||||
|
# allows it
|
||||||
|
StrRe("(@#chan1 @#chan2|@#chan2 @#chan1) ?"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
elif m.command == RPL_WHOISSPECIAL:
|
elif m.command == RPL_WHOISSPECIAL:
|
||||||
|
|
Loading…
Reference in New Issue