Loading tools/aapt2/ResourceUtils.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -512,7 +512,7 @@ std::unique_ptr<BinaryPrimitive> MakeBool(bool val) { } std::unique_ptr<BinaryPrimitive> TryParseInt(const StringPiece& str) { std::u16string str16 = util::Utf8ToUtf16(str); std::u16string str16 = util::Utf8ToUtf16(util::TrimWhitespace(str)); android::Res_value value; if (!android::ResTable::stringToInt(str16.data(), str16.size(), &value)) { return {}; Loading @@ -521,7 +521,7 @@ std::unique_ptr<BinaryPrimitive> TryParseInt(const StringPiece& str) { } std::unique_ptr<BinaryPrimitive> TryParseFloat(const StringPiece& str) { std::u16string str16 = util::Utf8ToUtf16(str); std::u16string str16 = util::Utf8ToUtf16(util::TrimWhitespace(str)); android::Res_value value; if (!android::ResTable::stringToFloat(str16.data(), str16.size(), &value)) { return {}; Loading tools/aapt2/ResourceUtils_test.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ TEST(ResourceUtilsTest, ParseBool) { EXPECT_THAT(ResourceUtils::ParseBool("false"), Eq(Maybe<bool>(false))); EXPECT_THAT(ResourceUtils::ParseBool("FALSE"), Eq(Maybe<bool>(false))); EXPECT_THAT(ResourceUtils::ParseBool("False"), Eq(Maybe<bool>(false))); EXPECT_THAT(ResourceUtils::ParseBool(" False\n "), Eq(Maybe<bool>(false))); } TEST(ResourceUtilsTest, ParseResourceName) { Loading Loading @@ -199,4 +201,16 @@ TEST(ResourceUtilsTest, EmptyIsBinaryPrimitive) { ASSERT_THAT(ResourceUtils::TryParseNullOrEmpty("@empty"), Pointee(ValueEq(BinaryPrimitive(Res_value::TYPE_NULL, Res_value::DATA_NULL_EMPTY)))); } TEST(ResourceUtilsTest, ItemsWithWhitespaceAreParsedCorrectly) { EXPECT_THAT(ResourceUtils::TryParseItemForAttribute(" 12\n ", ResTable_map::TYPE_INTEGER), Pointee(ValueEq(BinaryPrimitive(Res_value::TYPE_INT_DEC, 12u)))); EXPECT_THAT(ResourceUtils::TryParseItemForAttribute(" true\n ", ResTable_map::TYPE_BOOLEAN), Pointee(ValueEq(BinaryPrimitive(Res_value::TYPE_INT_BOOLEAN, 0xffffffffu)))); const float expected_float = 12.0f; const uint32_t expected_float_flattened = *(uint32_t*)&expected_float; EXPECT_THAT(ResourceUtils::TryParseItemForAttribute(" 12.0\n ", ResTable_map::TYPE_FLOAT), Pointee(ValueEq(BinaryPrimitive(Res_value::TYPE_FLOAT, expected_float_flattened)))); } } // namespace aapt tools/aapt2/readme.md +1 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ ## Version 2.18 ### `aapt2 ...` - Fixed issue where enum values were interpreted as integers and range checked. (bug 62358540) - Fixed issue where ints and floats with trailing whitespace would not be parsed. (bug 62902869) ## Version 2.17 ### `aapt2 ...` Loading Loading
tools/aapt2/ResourceUtils.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -512,7 +512,7 @@ std::unique_ptr<BinaryPrimitive> MakeBool(bool val) { } std::unique_ptr<BinaryPrimitive> TryParseInt(const StringPiece& str) { std::u16string str16 = util::Utf8ToUtf16(str); std::u16string str16 = util::Utf8ToUtf16(util::TrimWhitespace(str)); android::Res_value value; if (!android::ResTable::stringToInt(str16.data(), str16.size(), &value)) { return {}; Loading @@ -521,7 +521,7 @@ std::unique_ptr<BinaryPrimitive> TryParseInt(const StringPiece& str) { } std::unique_ptr<BinaryPrimitive> TryParseFloat(const StringPiece& str) { std::u16string str16 = util::Utf8ToUtf16(str); std::u16string str16 = util::Utf8ToUtf16(util::TrimWhitespace(str)); android::Res_value value; if (!android::ResTable::stringToFloat(str16.data(), str16.size(), &value)) { return {}; Loading
tools/aapt2/ResourceUtils_test.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ TEST(ResourceUtilsTest, ParseBool) { EXPECT_THAT(ResourceUtils::ParseBool("false"), Eq(Maybe<bool>(false))); EXPECT_THAT(ResourceUtils::ParseBool("FALSE"), Eq(Maybe<bool>(false))); EXPECT_THAT(ResourceUtils::ParseBool("False"), Eq(Maybe<bool>(false))); EXPECT_THAT(ResourceUtils::ParseBool(" False\n "), Eq(Maybe<bool>(false))); } TEST(ResourceUtilsTest, ParseResourceName) { Loading Loading @@ -199,4 +201,16 @@ TEST(ResourceUtilsTest, EmptyIsBinaryPrimitive) { ASSERT_THAT(ResourceUtils::TryParseNullOrEmpty("@empty"), Pointee(ValueEq(BinaryPrimitive(Res_value::TYPE_NULL, Res_value::DATA_NULL_EMPTY)))); } TEST(ResourceUtilsTest, ItemsWithWhitespaceAreParsedCorrectly) { EXPECT_THAT(ResourceUtils::TryParseItemForAttribute(" 12\n ", ResTable_map::TYPE_INTEGER), Pointee(ValueEq(BinaryPrimitive(Res_value::TYPE_INT_DEC, 12u)))); EXPECT_THAT(ResourceUtils::TryParseItemForAttribute(" true\n ", ResTable_map::TYPE_BOOLEAN), Pointee(ValueEq(BinaryPrimitive(Res_value::TYPE_INT_BOOLEAN, 0xffffffffu)))); const float expected_float = 12.0f; const uint32_t expected_float_flattened = *(uint32_t*)&expected_float; EXPECT_THAT(ResourceUtils::TryParseItemForAttribute(" 12.0\n ", ResTable_map::TYPE_FLOAT), Pointee(ValueEq(BinaryPrimitive(Res_value::TYPE_FLOAT, expected_float_flattened)))); } } // namespace aapt
tools/aapt2/readme.md +1 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ ## Version 2.18 ### `aapt2 ...` - Fixed issue where enum values were interpreted as integers and range checked. (bug 62358540) - Fixed issue where ints and floats with trailing whitespace would not be parsed. (bug 62902869) ## Version 2.17 ### `aapt2 ...` Loading