From a9eeb29b9bd32309a99ff336ae1ed247f75d9029 Mon Sep 17 00:00:00 2001 From: official-techsupport <98240022+official-techsupport@users.noreply.github.com> Date: Wed, 31 Aug 2022 00:19:53 +0300 Subject: [PATCH] fix showmore quadratic behavior (#343) --- files/helpers/regex.py | 5 +++-- files/helpers/sanitize.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 1d85db1b89..c27329d6ab 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -91,7 +91,8 @@ reddit_domain_regex = re.compile("(^|\s|\()https?:\/\/(reddit\.com|new\.reddit.c color_regex = re.compile("[a-z0-9]{6}", flags=re.A) -showmore_regex = re.compile("(.{3000,40000}?

)(

.*)", flags=re.A) +# lazy match on the {}?, only match if there is trailing text +showmore_regex = re.compile("^(.{3000,40000}?

)(

.*)", flags=re.A) search_token_regex = re.compile('"([^"]*)"|(\S+)', flags=re.A) @@ -145,4 +146,4 @@ def command_regex_matcher(match, upper=False): if match.group(2) == 'roll': color = tuple(choices(range(256), k=3)) result = f'Your roll: {result}' - return match.group(1) + result \ No newline at end of file + return match.group(1) + result diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index d00e84749a..da1a600b58 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -373,7 +373,7 @@ def sanitize(sanitized, edit=False, limit_pings=0, showmore=True): sanitized = sanitized.replace('\n','') if showmore and len(sanitized) > 5000: - sanitized = showmore_regex.sub(r'\1

\2', sanitized) + sanitized = showmore_regex.sub(r'\1

\2', sanitized, count=1) return sanitized.strip()