summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jackal Guo <jackalguo@google.com> 2021-10-06 15:50:33 +0800
committer Jackal Guo <jackalguo@google.com> 2021-10-07 12:56:27 +0800
commitc90f42c80fc9472ad1b46402672c0444b0365f49 (patch)
tree137db5fae90a134408ccd565620151d8b22350a8
parenta2871f84e911eae02864e1b998f8bc6d344f37d5 (diff)
Escape single quotes in aapt2
Using #normalizeForOutput to normalize a string for output in order to escape some special char. Fix: 140373430 Test: atest libaapt_tests aapt2_tests Change-Id: Ic49dbaaccd8e4b1c51a87de9f0e2e5f4a8da7d3d
-rw-r--r--tools/aapt2/xml/XmlDom.cpp3
-rw-r--r--tools/aapt2/xml/XmlDom_test.cpp13
2 files changed, 15 insertions, 1 deletions
diff --git a/tools/aapt2/xml/XmlDom.cpp b/tools/aapt2/xml/XmlDom.cpp
index 8b7eadf9fac9..dd60f1717de7 100644
--- a/tools/aapt2/xml/XmlDom.cpp
+++ b/tools/aapt2/xml/XmlDom.cpp
@@ -349,7 +349,8 @@ std::unique_ptr<XmlResource> Inflate(const void* data, size_t len, std::string*
size_t len;
const char16_t* str16 = tree.getText(&len);
if (str16) {
- text->text = util::Utf16ToUtf8(StringPiece16(str16, len));
+ text->text =
+ ResTable::normalizeForOutput(util::Utf16ToUtf8(StringPiece16(str16, len)).c_str());
}
CHECK(!node_stack.empty());
node_stack.top()->AppendChild(std::move(text));
diff --git a/tools/aapt2/xml/XmlDom_test.cpp b/tools/aapt2/xml/XmlDom_test.cpp
index 6c717dcd84c8..3a2d656240bb 100644
--- a/tools/aapt2/xml/XmlDom_test.cpp
+++ b/tools/aapt2/xml/XmlDom_test.cpp
@@ -139,6 +139,19 @@ TEST(XmlDomTest, XmlEscapeSequencesAreParsed) {
EXPECT_THAT(attr->value, Eq("\""));
}
+TEST(XmlDomTest, XmlEscapeSingleQuotes) {
+ std::unique_ptr<XmlResource> doc = test::BuildXmlDom(R"(
+ <foo><![CDATA[oh no' (line=1001)
+E: this-is-not-an-element (line=88)
+ T: 'blah]]></foo>)");
+
+ Element* el = doc->root.get();
+ Text* text = xml::NodeCast<xml::Text>(el->children[0].get());
+ ASSERT_THAT(text, NotNull());
+ EXPECT_THAT(text->text,
+ Eq("oh no' (line=1001)\nE: this-is-not-an-element (line=88)\n T: 'blah"));
+}
+
class TestVisitor : public PackageAwareVisitor {
public:
using PackageAwareVisitor::Visit;