Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c90f42c8 authored by Jackal Guo's avatar Jackal Guo
Browse files

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
parent a2871f84
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -349,7 +349,8 @@ std::unique_ptr<XmlResource> Inflate(const void* data, size_t len, std::string*
        size_t len;
        size_t len;
        const char16_t* str16 = tree.getText(&len);
        const char16_t* str16 = tree.getText(&len);
        if (str16) {
        if (str16) {
          text->text = util::Utf16ToUtf8(StringPiece16(str16, len));
          text->text =
              ResTable::normalizeForOutput(util::Utf16ToUtf8(StringPiece16(str16, len)).c_str());
        }
        }
        CHECK(!node_stack.empty());
        CHECK(!node_stack.empty());
        node_stack.top()->AppendChild(std::move(text));
        node_stack.top()->AppendChild(std::move(text));
+13 −0
Original line number Original line Diff line number Diff line
@@ -139,6 +139,19 @@ TEST(XmlDomTest, XmlEscapeSequencesAreParsed) {
  EXPECT_THAT(attr->value, Eq("\""));
  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 {
class TestVisitor : public PackageAwareVisitor {
 public:
 public:
  using PackageAwareVisitor::Visit;
  using PackageAwareVisitor::Visit;