Browse Source

Be more lenient with what tag names can be

Getty Ritter 4 years ago
parent
commit
d6dab1d728
2 changed files with 9 additions and 1 deletions
  1. 3 1
      lc/model.py
  2. 6 0
      tests/model.py

+ 3 - 1
lc/model.py

@@ -227,9 +227,11 @@ class Tag(Model):
         while (p := p.parent) :
             yield p
 
+    BAD_TAG_CHARS = set("{}[]\\()#?")
+
     @staticmethod
     def is_valid_tag_name(tag_name: str) -> bool:
-        return all((c.isalnum() or c == "/" for c in tag_name))
+        return all((c not in Tag.BAD_TAG_CHARS for c in tag_name))
 
     @staticmethod
     def get_or_create_tag(user: User, tag_name: str) -> "Tag":

+ 6 - 0
tests/model.py

@@ -101,6 +101,12 @@ class Testdb:
         tag_names = {t.tag.name for t in l.tags}  # type: ignore
         assert tag_names == {"food", "food/bread", "food/bread/rye"}
 
+    def test_bad_tag(self):
+        u = self.mk_user()
+        req = r.Link("http://foo.com", "foo", "", False, ["foo{bar}"])
+        with pytest.raises(e.BadTagName):
+            l = m.Link.from_request(u, req)
+
     def test_create_invite(self):
         u = self.mk_user()
         invite = m.UserInvite.manufacture(u)