mirror of
https://gitlab.com/tildes/tildes.git
synced 2026-04-16 06:18:34 +02:00
Strip trailing periods from topic titles
Note that this will also prevent a title from ending with "...". I did a search for all titles that ended in that, and none of them seemed essential (and probably should have been removed), so I think this should be fine.
This commit is contained in:
@@ -45,6 +45,13 @@ def test_whitespace_trimmed(title_schema):
|
||||
assert result["title"] == "actual title"
|
||||
|
||||
|
||||
def test_trailing_periods_trimmed(title_schema):
|
||||
"""Ensure trailing periods on a title are removed."""
|
||||
title = "This is an interesting story."
|
||||
result = title_schema.load({"title": title})
|
||||
assert not result["title"].endswith(".")
|
||||
|
||||
|
||||
def test_consecutive_whitespace_removed(title_schema):
|
||||
"""Ensure consecutive whitespace in a title is compressed."""
|
||||
title = "sure are \n a lot of spaces"
|
||||
|
||||
@@ -36,6 +36,18 @@ class TopicSchema(Schema):
|
||||
user = Nested(UserSchema, dump_only=True)
|
||||
group = Nested(GroupSchema, dump_only=True)
|
||||
|
||||
@pre_load
|
||||
def prepare_title(self, data: dict, many: bool, partial: Any) -> dict:
|
||||
"""Prepare the title before it's validated."""
|
||||
# pylint: disable=unused-argument
|
||||
if "title" not in data:
|
||||
return data
|
||||
|
||||
# strip any trailing periods
|
||||
data["title"] = data["title"].rstrip(".")
|
||||
|
||||
return data
|
||||
|
||||
@pre_load
|
||||
def prepare_tags(self, data: dict, many: bool, partial: Any) -> dict:
|
||||
"""Prepare the tags before they're validated."""
|
||||
|
||||
Reference in New Issue
Block a user