From cea200852db7dd18fca4a7aa52fc25bb6f81560f Mon Sep 17 00:00:00 2001 From: Deimos Date: Mon, 18 Mar 2019 20:07:15 -0600 Subject: [PATCH] Don't linkify group refs starting with a number This was a little more strict before and would only skip linkification if the entire path was digits and/or periods. However, I've seen it still hitting some people if they write things like "~100k". It's very unlikely that we're ever going to have a top-level group with a name starting with a number, so let's just skip linkification for all instances where a number is the first thing. --- tildes/tests/test_markdown.py | 2 +- tildes/tildes/lib/markdown.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tildes/tests/test_markdown.py b/tildes/tests/test_markdown.py index 333110f..3e18196 100644 --- a/tildes/tests/test_markdown.py +++ b/tildes/tests/test_markdown.py @@ -250,7 +250,7 @@ def test_invalid_group_reference_not_linkified(): def test_approximately_tilde_not_linkified(): """Ensure a tilde in front of a number doesn't linkify.""" - markdown = "Mix in ~2 cups of flour and ~1.5 tbsp of sugar." + markdown = "Mix in ~2 cups of flour and ~1.5 tbsp of sugar with ~3kg of meat." processed = convert_markdown_to_safe_html(markdown) assert " - if is_valid_group_path(group_path) and not is_numeric: + # Even though they're technically valid paths, we don't want to linkify anything + # starting with a number like "~10" or "~4.5", since that's just going to be + # someone using it in the "approximately" sense. This will be a problem if a + # top-level group's name ever starts with a number, but I think that's unlikely. + is_ignored = group_path.startswith(tuple("0123456789")) + + # if it's a valid group path and not ignored by the above logic, convert to + if is_valid_group_path(group_path) and not is_ignored: return [ { "type": "StartTag",