Skip to content

Commit 081a671

Browse files
committed
Removed extra new-line from Android resources formatter
1 parent eb4f581 commit 081a671

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

python_twine/tests/test_formatters.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ def test_writer_escape_angle_bracket(self, formatter):
230230

231231
assert formatter.escape_value('<![C DATA[ <![CDATA[') == '&lt;![C DATA[ <![CDATA['
232232

233-
def test_writer_escape_newline(self, formatter):
234-
"""Test '\\n' escaping."""
235-
assert formatter.escape_value('\\n') == '\n\\n'
236-
assert formatter.escape_value('Downloading %@. You can now\\nproceed to the map.') == 'Downloading %\\@. You can now\n\\nproceed to the map.'
233+
def test_writer_escape_at(self, formatter):
234+
"""Test '@' escaping."""
235+
assert formatter.escape_value('Downloading %@. You can now\\nproceed to the map.') == 'Downloading %\\@. You can now\\nproceed to the map.'
236+
assert formatter.escape_value('Press @strings/escape to stop.') == 'Press @strings/escape to stop.'
237237

238-
cdata = '<![CDATA[ New\\nline\n ]]>'
238+
cdata = '<![CDATA[ New\nline\\n ]]>'
239239
assert formatter.escape_value(cdata) == cdata
240240

241241
class TestAppleFormatter(FormatterTestData):

python_twine/twine/formatters/android.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ def unescape_value(value: str) -> str:
225225
value = value.replace("\\@", "@")
226226

227227
# Unescape \n
228-
value = value.replace("\n\\n", "\n")
228+
value = value.replace("\n\\n", "\n") # Old escape format
229+
value = value.replace("\\n", "\n")
229230

230231
# Convert \u0020 space escapes
231232
def replace_spaces(match):
@@ -294,11 +295,6 @@ def is_non_tag(result:str, i:int):
294295
lambda i: is_non_tag(result, i)
295296
)
296297

297-
# Escape newlines (unless in CDATA)
298-
result = replace_with_filter(result, "\\n", "\n\\n",
299-
lambda i: not inside_cdata(result, i)
300-
)
301-
302298
# escape non resource identifier @ signs (http://developer.android.com/guide/topics/resources/accessing-resources.html#ResourcesFromXml)
303299
resource_identifier_regex = re.compile(r"@(?!([a-z\.]+:)?[a-z+]+\/[a-zA-Z_]+)") # @[<package_name>:]<resource_type>/<resource_name>
304300
result = resource_identifier_regex.sub(r"\\@", result)

0 commit comments

Comments
 (0)