From 633d796623f84046ebf9baeccd1ba5bcefc16313 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Mon, 11 Jun 2018 15:29:21 -0700 Subject: [PATCH] AAPT2: Fix raw string parsing Trim whitespace of raw strings when parsing xml values. This change trims the whitespace of style items. For example: com.helloworld.Inflater This will be trimmed to not include a trailing whitespace. Bug: 109666819 Test: aapt2_tests Change-Id: I0c1fbb3abdc7e609316c92e59ccaf0573b07e5a7 --- tools/aapt2/ResourceParser.cpp | 3 ++- tools/aapt2/ResourceParser_test.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp index 089c9e2845701..ef5912bfad928 100644 --- a/tools/aapt2/ResourceParser.cpp +++ b/tools/aapt2/ResourceParser.cpp @@ -777,7 +777,8 @@ std::unique_ptr 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( - table_->string_pool.MakeRef(raw_value, StringPool::Context(config_))); + table_->string_pool.MakeRef(util::TrimWhitespace(raw_value), + StringPool::Context(config_))); } return {}; } diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp index 41b4041efb7af..5711dc35d4231 100644 --- a/tools/aapt2/ResourceParser_test.cpp +++ b/tools/aapt2/ResourceParser_test.cpp @@ -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"( + )"; + ASSERT_TRUE(TestParse(input)); + + Style* style = test::GetValue