From af2760ebe784a2342c749a31641344c5f9922ee6 Mon Sep 17 00:00:00 2001 From: jamesconwaydev <148910373+jamesconwaydev@users.noreply.github.com> Date: Fri, 6 Nov 2026 10:22:17 -0700 Subject: [PATCH] fix(submit): keep cleaned descriptions stable when cleaned again --- scripts/devstream/description.py | 9 ++++++--- scripts/tests/test_description.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/devstream/description.py b/scripts/devstream/description.py index 1d1e565..286638e 100644 --- a/scripts/devstream/description.py +++ b/scripts/devstream/description.py @@ -8,7 +8,9 @@ VARIATION = re.compile("[\ufe00-\ufe0f]") ZWJ = "\u200d" # A zero-width joiner between two emoji builds one emoji (a family, say), so it survives the stripping. -EMOJI_ZWJ = re.compile("(?<=[\U0001f000-\U0001faff\u2600-\u27bf\ufe00-\ufe0f])\u200d(?=[\U0001f000-\U0001faff\u2600-\u27bf])") +# A variation selector counts only straight after an emoji: it's stripped, so the joiner must still sit by one. +EMOJI_ZWJ = re.compile("(?:(?<=[\U0001f000-\U0001faff\u2600-\u27bf])|(?<=[\U0001f000-\U0001faff\u2600-\u27bf][\ufe00-\ufe0f]))" + "\u200d(?=[\U0001f000-\U0001faff\u2600-\u27bf])") # Only names that are not real TLDs a spammer would use; Node.js and Vue.js rely on "js". NOT_TLDS = {"js", "ts", "py", "md", "rb"} DOMAIN = re.compile(r"(? tuple[str | None, str | None]: if _emoji_run_too_long(t): return None, "Descriptions can't have more than 2 emoji in a row." t = " ".join(VARIATION.sub("", t).split()) - body = t.rstrip("!?,;: ") + # The whole trailing run in one go, dots included, so a second pass finds nothing left to strip. + body = t.rstrip("!?,;:. ") # A question keeps one question mark; anything else ends in a full stop. - final = body.rstrip(".") + ("?" if "?" in t[len(body):] else ".") + final = body + ("?" if "?" in t[len(body):] else ".") # Both limits cover the finished text: a 140-character input with no period # would be stored at 141, and "Toolkit!!!" shrinks to an 8-character "Toolkit.". if not MIN_LEN <= len(final) <= MAX_LEN: diff --git a/scripts/tests/test_description.py b/scripts/tests/test_description.py index 24df6ef..19d0bf4 100644 --- a/scripts/tests/test_description.py +++ b/scripts/tests/test_description.py @@ -48,6 +48,8 @@ def test_output_is_a_fixed_point(self): "y" * 139, "z" * 140, "w" * 139 + ".", "v" * 141, "short", "abcdefghi!", "abcdefghij!", "Mixed ending?.!", "Tabs\tand\nnewlines in it", "Dots... in the middle... end...", "Questions? Yes, answered here?", "Ending with spaces and bang ! ", + # Found by the fuzzer: a dot and a space inside the trailing run, and a joiner after a lone selector. + "f\u2764...\u2764e-Z!gg!bdgf::fb.a:.?", "Xc ebb!-. .?!", "eedf\ufe0f\u200d\u2764? g;\U0001f468", # The added period turns a trailing "www" into "www.", which must not read as a link. "A short history of the www", "Mirror of the WWW!", ]