Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f326759 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Do not convert whitespace chars above max char to regular space

Using isspace and iswspace on characters above the maximum char value is
undefined. This change makes aapt2 use isspace like aapt and only trims
whitespace characters at or below the maximum char value like aapt2.

Bug: 121017795
Test: aapt2_tests
Change-Id: I015e4b77f0ff53e409e880fcf9ae104ba3444d1a
parent 41469c3b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -183,11 +183,11 @@ TEST_F(ResourceParserTest, ParseStringTruncateASCII) {
  EXPECT_THAT(str->untranslatable_sections, IsEmpty());

  // Preserve non-ASCII whitespace including extended ASCII characters
  EXPECT_TRUE(TestParse(R"(<string name="foo3">&#160;Hello&#160;</string>)"));
  EXPECT_TRUE(TestParse(R"(<string name="foo3">&#160;Hello&#x202F;World&#160;</string>)"));

  str = test::GetValue<String>(&table_, "string/foo3");
  ASSERT_THAT(str, NotNull());
  EXPECT_THAT(*str->value, StrEq("\xC2\xA0Hello\xC2\xA0"));
  EXPECT_THAT(*str->value, StrEq("\xC2\xA0Hello\xE2\x80\xAFWorld\xC2\xA0"));
  EXPECT_THAT(str->untranslatable_sections, IsEmpty());

  EXPECT_TRUE(TestParse(R"(<string name="foo4">2005年6月1日</string>)"));
+2 −3
Original line number Diff line number Diff line
@@ -40,8 +40,6 @@ using ::android::base::StringPrintf;
namespace aapt {
namespace ResourceUtils {

constexpr int32_t kNonBreakingSpace = 0xa0;

Maybe<ResourceName> ToResourceName(
    const android::ResTable::resource_name& name_in) {
  // TODO: Remove this when ResTable and AssetManager(1) are removed from AAPT2
@@ -854,7 +852,8 @@ StringBuilder& StringBuilder::AppendText(const std::string& text) {
  Utf8Iterator iter(text);
  while (iter.HasNext()) {
    char32_t codepoint = iter.Next();
    if (!preserve_spaces_ && !quote_ && codepoint != kNonBreakingSpace && iswspace(codepoint)) {
    if (!preserve_spaces_ && !quote_ && (codepoint <= std::numeric_limits<char>::max())
                                         && isspace(static_cast<char>(codepoint))) {
      if (!last_codepoint_was_space_) {
        // Emit a space if it's the first.
        xml_string_.text += ' ';