Skip to content

Commit

Permalink
Merge pull request #333 from transifex/TX-15425-anrdoid_accept_newlines
Browse files Browse the repository at this point in the history
Accept newlines and tabs in android v3
  • Loading branch information
kbairak authored Apr 25, 2024
2 parents ad4747b + 5d5fea7 commit 5df64ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 62 deletions.
57 changes: 7 additions & 50 deletions openformats/formats/android_unescaped.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from openformats.exceptions import ParseError
from openformats.formats.android import AndroidHandler
from ..utils.xml import NewDumbXml as DumbXml
from ..utils.xmlutils import XMLUtils
from ..strings import OpenString


class AndroidUnescapedHandler(AndroidHandler):
Expand All @@ -23,45 +21,7 @@ def _create_string(self, name, text, comment, product, child, pluralized=False):
else None.
"""
AndroidUnescapedHandler._check_unescaped_characters(text)
if XMLUtils.validate_not_empty_string(
self.transcriber,
text,
child,
error_context={"main_tag": "plural", "child_tag": "item"},
):
if (name, product) in self.existing_hashes:
if child.tag in self.existing_hashes[(name, product)]:
format_dict = {"name": name, "child_tag": child.tag}
if product:
msg = (
"Duplicate `tag_name` ({child_tag}) for `name`"
" ({name}) and `product` ({product}) "
"found on line {line_number}"
)
format_dict["product"] = product
else:
msg = (
"Duplicate `tag_name` ({child_tag}) for `name`"
" ({name}) specify a product to differentiate"
)
XMLUtils.raise_error(
self.transcriber, child, msg, context=format_dict
)
else:
product += child.tag
# Create OpenString
string = OpenString(
name,
text,
context=product,
order=next(self.order_counter),
developer_comment=comment,
pluralized=pluralized,
)
self.existing_hashes.setdefault((name, product), [])
self.existing_hashes[(name, product)].append(child.tag)
return string
return None
return super()._create_string(name, text, comment, product, child, pluralized)

@staticmethod
def _check_unescaped_characters(text):
Expand Down Expand Up @@ -94,16 +54,13 @@ def _check_unescaped_characters_in_simple_string(text):
r'(?<!\\)"',
r"(?<!\\)@",
r"(?<!\\)\?",
r"(?<!\\)\n",
r"(?<!\\)\t",
]

for pattern in not_allowed_unescaped:
if re.search(pattern, protected_string):
raise ParseError(
"You have one or more unescaped characters from the following "
f"list ', \", @, ?, \\n, \\t in the string : {text}"
)
full_pattern = "|".join(not_allowed_unescaped)
if re.search(full_pattern, protected_string):
raise ParseError(
"You have one or more unescaped characters from the following list: ', "
f'", @, ?, \\n, \\t in the string: {text!r}'
)

@staticmethod
def _check_unescaped_characters_in_plural_string(text):
Expand Down
12 changes: 0 additions & 12 deletions openformats/tests/formats/android/test_android_unescaped.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,3 @@ def test_create_string_raises_error(self):
AndroidUnescapedHandler._check_unescaped_characters,
unescaped_string,
)
unescaped_string = "some \n string"
self.assertRaises(
ParseError,
AndroidUnescapedHandler._check_unescaped_characters,
unescaped_string,
)
unescaped_string = "some \t string"
self.assertRaises(
ParseError,
AndroidUnescapedHandler._check_unescaped_characters,
unescaped_string,
)

0 comments on commit 5df64ed

Please sign in to comment.