From fc3874ac821b63b07fef089667e4afe3c4528aa5 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Tue, 28 May 2019 16:30:17 -0700 Subject: Empty attribute values in styles should be strings In aapt1, if you specified the value of an attribute in a style as an empty string (eg. ), the encoded value would be an empty string. In aapt2 currently, @null is encoded instead. This change restores aapt1 behavior. Use @null explicitly if the desired value is to be @null. Bug: 133450400 Test: manual comparison of APK created by aapt1 and aapt2 $ aapt p -M AndroidManifest.xml -F out1.apk -S res -f $ aapt2 compile --dir res-o compiled.flata $ aapt2 link --manifest AndroidManifest.xml -o out2.apk compiled.flata $ aapt2 dump out2.apk Change-Id: I8aa0ba30379dac0b1229da525abbc5482f40114b --- tools/aapt2/ResourceParser.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'tools/aapt2/ResourceParser.cpp') diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp index 45cea8190844..859fe80c5ce7 100644 --- a/tools/aapt2/ResourceParser.cpp +++ b/tools/aapt2/ResourceParser.cpp @@ -769,16 +769,14 @@ std::unique_ptr ResourceParser::ParseXml(xml::XmlPullParser* parser, return std::move(string); } - // If the text is empty, and the value is not allowed to be a string, encode it as a @null. - if (util::TrimWhitespace(raw_value).empty()) { - return ResourceUtils::MakeNull(); - } - 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(util::TrimWhitespace(raw_value), StringPool::Context(config_))); + } else if (util::TrimWhitespace(raw_value).empty()) { + // If the text is empty, and the value is not allowed to be a string, encode it as a @null. + return ResourceUtils::MakeNull(); } return {}; } -- cgit v1.2.3-59-g8ed1b