Commit 355dab8a authored by Trevor Perrier's avatar Trevor Perrier Committed by Commit Bot

[grit] always remove ByteOrderMark marks

This CL changes grit MessageNode so that ByteOrderMarks are always
removed from message translations.

This will prevent lint errors due to accidental BOM characters in xtb
files that will break the build on TC imports.

Currently the BOM appears in 8 string translations. This is after
several strings had been re-translated to remove the BOM.

This CL has been tested with all ByteOrderMark suppressions removed
from build/android/lint/suppressions.xml and there are no BOM related
lint errors.

Bug: 1033305
Change-Id: Ia3d7a4e449ed717f19a4eea013e4ca1b4113e5c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2039342Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarMegan Jablonski <megjablon@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738821}
parent e6db9138
...@@ -268,6 +268,8 @@ class MessageNode(base.ContentNode): ...@@ -268,6 +268,8 @@ class MessageNode(base.ContentNode):
).GetRealContent() ).GetRealContent()
if self._replace_ellipsis: if self._replace_ellipsis:
msg = _ELLIPSIS_PATTERN.sub(_ELLIPSIS_SYMBOL, msg) msg = _ELLIPSIS_PATTERN.sub(_ELLIPSIS_SYMBOL, msg)
# Always remove all byte order marks (\uFEFF) https://crbug.com/1033305
msg = msg.replace(u'\uFEFF','')
return msg.replace('[GRITLANGCODE]', lang) return msg.replace('[GRITLANGCODE]', lang)
def NameOrOffset(self): def NameOrOffset(self):
......
...@@ -98,6 +98,17 @@ class MessageUnittest(unittest.TestCase): ...@@ -98,6 +98,17 @@ class MessageUnittest(unittest.TestCase):
content = msg.Translate('en') content = msg.Translate('en')
self.failUnlessEqual(u'A...B.... %s\u2026 B\u2026 C\u2026', content) self.failUnlessEqual(u'A...B.... %s\u2026 B\u2026 C\u2026', content)
def testRemoveByteOrderMark(self):
root = util.ParseGrdForUnittest(u'''
<messages>
<message name="IDS_HAS_BOM" desc="">
\uFEFFThis\uFEFF i\uFEFFs OK\uFEFF
</message>
</messages>''')
msg, = root.GetChildrenOfType(message.MessageNode)
content = msg.Translate('en')
self.failUnlessEqual(u'This is OK', content)
def testPlaceholderHasTooManyExamples(self): def testPlaceholderHasTooManyExamples(self):
try: try:
util.ParseGrdForUnittest("""\ util.ParseGrdForUnittest("""\
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment