Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions python_twine/tests/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ def test_writer_escape_angle_bracket(self, formatter):

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

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

cdata = '<![CDATA[ New\\nline\n ]]>'
cdata = '<![CDATA[ New\nline\\n ]]>'
assert formatter.escape_value(cdata) == cdata

class TestAppleFormatter(FormatterTestData):
Expand Down
8 changes: 2 additions & 6 deletions python_twine/twine/formatters/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def unescape_value(value: str) -> str:
value = value.replace("\\@", "@")

# Unescape \n
value = value.replace("\n\\n", "\n")
value = value.replace("\n\\n", "\n") # Old escape format
value = value.replace("\\n", "\n")

# Convert \u0020 space escapes
def replace_spaces(match):
Expand Down Expand Up @@ -294,11 +295,6 @@ def is_non_tag(result:str, i:int):
lambda i: is_non_tag(result, i)
)

# Escape newlines (unless in CDATA)
result = replace_with_filter(result, "\\n", "\n\\n",
lambda i: not inside_cdata(result, i)
)

# escape non resource identifier @ signs (http://developer.android.com/guide/topics/resources/accessing-resources.html#ResourcesFromXml)
resource_identifier_regex = re.compile(r"@(?!([a-z\.]+:)?[a-z+]+\/[a-zA-Z_]+)") # @[<package_name>:]<resource_type>/<resource_name>
result = resource_identifier_regex.sub(r"\\@", result)
Expand Down