Skip to content

Commit

Permalink
Runaway regex, catastrophic backtracking
Browse files Browse the repository at this point in the history
  • Loading branch information
RigglePrime committed Mar 12, 2023
1 parent c6b95ce commit 1122635
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "SS13-tools"
version = "2.2.0"
version = "2.2.1"
description = "Python toolchain for SS13"
authors = ["RigglePrime <[email protected]>", "tattle <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion ss13_tools/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.2.0'
__version__ = '2.2.1'
1 change: 0 additions & 1 deletion ss13_tools/log_buddy/expressions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
LOC_REGEX = r"\(\d{1,3},\d{1,3},\d{1,2}\)"
ADMIN_OSAY_EXP = r"made the ((?:\w+ ?)+) at ((?:\w+ ?)+) " + LOC_REGEX + r" say \"(.*)\"$"
ADMIN_STAT_CHANGE = r"((re-)|(de))?adminn?ed "
ADMIN_BUILD_MODE = r"has (entered|left) build mode."
HORRIBLE_HREF = r"<a href='\?priv_msg=\w+'>([\w ]+)<\/a>\/\((.+)\)"
Expand Down
16 changes: 10 additions & 6 deletions ss13_tools/log_buddy/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dateutil.parser import isoparse

from ss13_tools.byond import canonicalize
from ss13_tools.log_buddy.expressions import LOC_REGEX, ADMIN_BUILD_MODE, ADMIN_OSAY_EXP, ADMIN_STAT_CHANGE,\
from ss13_tools.log_buddy.expressions import LOC_REGEX, ADMIN_BUILD_MODE, ADMIN_STAT_CHANGE,\
HORRIBLE_HREF, GAME_I_LOVE_BOMBS, ADMINPRIVATE_NOTE, ADMINPRIVATE_BAN,\
LOG_PRETTY_LOC, LOG_PRETTY_STR, LOG_PRETTY_PATH
from ss13_tools.log_buddy.constants import LOG_COLOUR_SCARLET, LOG_COLOUR_RED, LOG_COLOUR_EMERALD,\
Expand Down Expand Up @@ -485,12 +485,16 @@ def parse_admin(self, log: str) -> None: # noqa: C901
self.agent = Player.parse_player(agent)
if re.search(ADMIN_BUILD_MODE, other):
self.admin_log_type = AdminLogType.BUILD_MODE
elif match := re.search(ADMIN_OSAY_EXP, other):
elif other.startswith("made the ") and ' say "' in other:
self.admin_log_type = AdminLogType.OBJECT_SAY
self.patient = Player(None, match[1])
self.location_name = match[2].strip()
self.text = match[3].strip()
self.__parse_and_set_location(other)
patient, other = other[9:].split(' at ', 1)
self.patient = Player(None, patient)
location_name, other = other.split(' say "')
loc_start = self.__parse_and_set_location(location_name)
if loc_start > 0:
location_name = location_name[:loc_start]
self.location_name = location_name.strip()
self.text = other.rstrip('"')
return
elif other.startswith("has created a command report: "):
self.admin_log_type = AdminLogType.COMMAND_REPORT
Expand Down

0 comments on commit 1122635

Please sign in to comment.