Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions scripts/devstream/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"(?<![\w.-])(?:[a-z0-9-]+\.)+([a-z]{2,24})(?![a-z0-9])", re.I)
Expand Down Expand Up @@ -96,9 +98,10 @@ def clean_description(text: str) -> 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:
Expand Down
2 changes: 2 additions & 0 deletions scripts/tests/test_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
]
Expand Down
Loading