Merge "AAPT2: Fix raw string parsing"

This commit is contained in:
Ryan Mitchell
2018-06-12 20:51:33 +00:00
committed by Android (Google) Code Review
2 changed files with 20 additions and 1 deletions

View File

@@ -777,7 +777,8 @@ std::unique_ptr<Item> ResourceParser::ParseXml(xml::XmlPullParser* parser,
if (allow_raw_value) {
// We can't parse this so return a RawString if we are allowed.
return util::make_unique<RawString>(
table_->string_pool.MakeRef(raw_value, StringPool::Context(config_)));
table_->string_pool.MakeRef(util::TrimWhitespace(raw_value),
StringPool::Context(config_)));
}
return {};
}

View File

@@ -497,6 +497,24 @@ TEST_F(ResourceParserTest, ParseStyleWithPackageAliasedItems) {
EXPECT_THAT(style->entries[0].key.name, Eq(make_value(test::ParseNameOrDie("android:attr/bar"))));
}
TEST_F(ResourceParserTest, ParseStyleWithRawStringItem) {
std::string input = R"(
<style name="foo">
<item name="bar">
com.helloworld.AppClass
</item>
</style>)";
ASSERT_TRUE(TestParse(input));
Style* style = test::GetValue<Style>(&table_, "style/foo");
ASSERT_THAT(style, NotNull());
EXPECT_THAT(style->entries[0].value, NotNull());
RawString* value = ValueCast<RawString>(style->entries[0].value.get());
EXPECT_THAT(value, NotNull());
EXPECT_THAT(*value->value, StrEq(R"(com.helloworld.AppClass)"));
}
TEST_F(ResourceParserTest, ParseStyleWithInferredParent) {
ASSERT_TRUE(TestParse(R"(<style name="foo.bar"/>)"));