AAPT2: Fix string escaping
We were processing escaped strings too early, before
parsing of values into types. Now the escaped strings get
processed when they are being flattened.
Bug: 37715376
Test: make aapt2_tests
Change-Id: Ic59aa2e3a20c40756c219752ff74b2a4f8a602ba
diff --git a/tools/aapt2/xml/XmlDom_test.cpp b/tools/aapt2/xml/XmlDom_test.cpp
index 0fc3cec6..fb18ea3 100644
--- a/tools/aapt2/xml/XmlDom_test.cpp
+++ b/tools/aapt2/xml/XmlDom_test.cpp
@@ -49,23 +49,26 @@
EXPECT_EQ(ns->namespace_prefix, "android");
}
-TEST(XmlDomTest, HandleEscapes) {
- std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDom(
- R"EOF(<shortcode pattern="\\d{5}">\\d{5}</shortcode>)EOF");
+// Escaping is handled after parsing of the values for resource-specific values.
+TEST(XmlDomTest, ForwardEscapes) {
+ std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDom(R"EOF(
+ <element value="\?hello" pattern="\\d{5}">\\d{5}</element>)EOF");
xml::Element* el = xml::FindRootElement(doc->root.get());
ASSERT_NE(nullptr, el);
xml::Attribute* attr = el->FindAttribute({}, "pattern");
ASSERT_NE(nullptr, attr);
+ EXPECT_EQ("\\\\d{5}", attr->value);
- EXPECT_EQ("\\d{5}", attr->value);
+ attr = el->FindAttribute({}, "value");
+ ASSERT_NE(nullptr, attr);
+ EXPECT_EQ("\\?hello", attr->value);
ASSERT_EQ(1u, el->children.size());
-
xml::Text* text = xml::NodeCast<xml::Text>(el->children[0].get());
ASSERT_NE(nullptr, text);
- EXPECT_EQ("\\d{5}", text->text);
+ EXPECT_EQ("\\\\d{5}", text->text);
}
} // namespace aapt