Skip to content

Commit

Permalink
Fix bug 1632206: Preserve whitespace in submitted translations (#1668)
Browse files Browse the repository at this point in the history
Add custom validation, which does not strip whitespace from the
translation field.
  • Loading branch information
mathjazz committed Aug 6, 2020
1 parent 11f2ea0 commit b91218b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pontoon/translations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ def clean_plural_form(self):
if self.cleaned_data["plural_form"] == "-1":
return None
return self.cleaned_data["plural_form"]

def clean_translation(self):
return self.data.get("translation", "")
15 changes: 15 additions & 0 deletions pontoon/translations/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,18 @@ def test_create_translation_form_clean_paths(entity_a, locale_a):
)
assert form.is_valid()
assert form.cleaned_data["paths"] == ["a/d.ext", "foo/bar"]


@pytest.mark.django_db
def test_create_translation_form_clean_translation(entity_a, locale_a):
form = CreateTranslationForm(
{
"entity": entity_a.pk,
"translation": " salut ",
"locale": locale_a.code,
"plural_form": "-1",
"original": "hello",
}
)
assert form.is_valid()
assert form.cleaned_data["translation"] == " salut "

0 comments on commit b91218b

Please sign in to comment.