Skip to content

Commit

Permalink
properties: fix mozila properties encoding space
Browse files Browse the repository at this point in the history
This ancient workaround for Pootle is no longer needed.

Fixes #3232
  • Loading branch information
nijel committed Mar 11, 2024
1 parent 2d601e7 commit e98250d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/translate/convert/test_po2prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_mozilla_all_whitespace(self):
proptemplate = """accesskey-accept=
accesskey-help=H
"""
propexpected = """accesskey-accept=
propexpected = r"""accesskey-accept=\u0020
accesskey-help=م
"""
propfile = self.merge2prop(proptemplate, posource, personality="mozilla")
Expand Down
6 changes: 3 additions & 3 deletions tests/translate/misc/test_quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def test_escapespace():

@staticmethod
def test_mozillaescapemarginspaces():
assert quote.mozillaescapemarginspaces(" ") == ""
assert quote.mozillaescapemarginspaces(" ") == r"\u0020"
assert quote.mozillaescapemarginspaces("A") == "A"
assert quote.mozillaescapemarginspaces(" abc ") == "\\u0020abc\\u0020"
assert quote.mozillaescapemarginspaces(" abc ") == "\\u0020 abc\\u0020"
assert quote.mozillaescapemarginspaces(" abc ") == r"\u0020abc\u0020"
assert quote.mozillaescapemarginspaces(" abc ") == r"\u0020 abc\u0020"

@staticmethod
def test_mozilla_control_escapes():
Expand Down
13 changes: 13 additions & 0 deletions tests/translate/storage/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,19 @@ def test_newlines_startend(self):
propregen = self.propregen(propsource)
assert propsource + "\n" == propregen

def test_space(self):
r"""Check that we preserve \n that appear at start and end of properties."""
propsource = r"""space=\u0020
endspace=,\u0020
"""
store = self.propparse(propsource, personality="mozilla")
assert len(store.units) == 2
assert store.units[0].source == " "
assert store.units[1].source == ", "
store.units[0].source = " "
store.units[1].source = ", "
assert bytes(store).decode("utf-8") == propsource

def test_whitespace_handling(self):
"""Check that we remove extra whitespace around property."""
whitespaces = (
Expand Down
7 changes: 0 additions & 7 deletions translate/misc/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,6 @@ def mozillaescapemarginspaces(source: str) -> str:
"""Escape leading and trailing spaces for Mozilla .properties files."""
if not source:
return ""

if len(source) == 1 and source.isspace():
# FIXME: This is hack for people using white-space to mark empty
# Mozilla strings translated, drop this once we have better way to
# handle this in Pootle.
return ""

if len(source) == 1:
return escapespace(source)
return escapespace(source[0]) + source[1:-1] + escapespace(source[-1])
Expand Down

0 comments on commit e98250d

Please sign in to comment.