mirror of https://github.com/progval/irctest.git
Make re.match actually check the whole string matches the pattern
This commit is contained in:
parent
e6d54db9ce
commit
9391a9128d
|
@ -15,7 +15,7 @@ TAG_ESCAPE = [
|
|||
unescape_tag_value = MultipleReplacer(dict(map(lambda x: (x[1], x[0]), TAG_ESCAPE)))
|
||||
|
||||
# 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]]:
|
||||
|
|
|
@ -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:
|
||||
return True
|
||||
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
|
||||
elif isinstance(expected, OptStrRe):
|
||||
if got is None:
|
||||
return True
|
||||
if not re.match(expected.regexp, got):
|
||||
if not re.match(expected.regexp + "$", got):
|
||||
return False
|
||||
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
|
||||
elif isinstance(expected, InsensitiveStr):
|
||||
if got is None or got.lower() != expected.string.lower():
|
||||
|
|
|
@ -56,7 +56,8 @@ class IsupportTestCase(cases.BaseServerTestCase):
|
|||
return
|
||||
|
||||
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(
|
||||
m,
|
||||
|
@ -117,5 +118,5 @@ class IsupportTestCase(cases.BaseServerTestCase):
|
|||
parts = self.server_support["TARGMAX"].split(",")
|
||||
for part in parts:
|
||||
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
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue