fix showmore quadratic behavior (#343)

remotes/1693045480750635534/spooky-22
official-techsupport 2022-08-31 00:19:53 +03:00 committed by GitHub
parent a3c0e39b39
commit a9eeb29b9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -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}?</p>)(<p>.*)", flags=re.A)
# lazy match on the {}?, only match if there is trailing text
showmore_regex = re.compile("^(.{3000,40000}?</p>)(<p>.*)", 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'<b style="color:rgb{color}">Your roll: {result}</b>'
return match.group(1) + result
return match.group(1) + result

View File

@ -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<p><button class="showmore" onclick="showmore()">SHOW MORE</button></p><d class="d-none">\2</d>', sanitized)
sanitized = showmore_regex.sub(r'\1<p><button class="showmore" onclick="showmore()">SHOW MORE</button></p><d class="d-none">\2</d>', sanitized, count=1)
return sanitized.strip()