summaryrefslogtreecommitdiff
path: root/tools/aapt2/util/Util.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-06-29 17:53:36 -0700
committerAdam Lesinski <adamlesinski@google.com>2017-07-07 13:23:55 -0700
commitfba0cf2950a91726e475fb180090cc25bcb11a7a (patch)
tree222ec9ccc4e1710e5a269edd2fffce60ca1692d7 /tools/aapt2/util/Util.cpp
parent66ea8400383d5737b996a136f3aead0965f7be3d (diff)
AAPT2: Fix processing of quotes in XML
When processing attributes in XML, quotes can't be used to mark a section as whitespace preserving, so the assumption should be that the entire string is whitespace preserving, which makes quote characters literals. Bug: 62840718 Bug: 62840406 Test: make aapt2_tests Change-Id: I4afff02148b5b8e78833abf1f323c2f5325d6155
Diffstat (limited to 'tools/aapt2/util/Util.cpp')
-rw-r--r--tools/aapt2/util/Util.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/tools/aapt2/util/Util.cpp b/tools/aapt2/util/Util.cpp
index 9fde1b474bf3..51a75d7556ad 100644
--- a/tools/aapt2/util/Util.cpp
+++ b/tools/aapt2/util/Util.cpp
@@ -327,6 +327,9 @@ static bool IsCodepointSpace(char32_t codepoint) {
return isspace(static_cast<char>(codepoint));
}
+StringBuilder::StringBuilder(bool preserve_spaces) : preserve_spaces_(preserve_spaces) {
+}
+
StringBuilder& StringBuilder::Append(const StringPiece& str) {
if (!error_.empty()) {
return *this;
@@ -372,14 +375,12 @@ StringBuilder& StringBuilder::Append(const StringPiece& str) {
}
last_char_was_escape_ = false;
- } else if (codepoint == U'"') {
+ } else if (!preserve_spaces_ && codepoint == U'"') {
if (!quote_ && trailing_space_) {
- // We found an opening quote, and we have
- // trailing space, so we should append that
+ // We found an opening quote, and we have trailing space, so we should append that
// space now.
if (trailing_space_) {
- // We had trailing whitespace, so
- // replace with a single space.
+ // We had trailing whitespace, so replace with a single space.
if (!str_.empty()) {
str_ += ' ';
}
@@ -388,7 +389,7 @@ StringBuilder& StringBuilder::Append(const StringPiece& str) {
}
quote_ = !quote_;
- } else if (codepoint == U'\'' && !quote_) {
+ } else if (!preserve_spaces_ && codepoint == U'\'' && !quote_) {
// This should be escaped.
error_ = "unescaped apostrophe";
return *this;
@@ -405,7 +406,7 @@ StringBuilder& StringBuilder::Append(const StringPiece& str) {
}
last_char_was_escape_ = true;
} else {
- if (quote_) {
+ if (preserve_spaces_ || quote_) {
// Quotes mean everything is taken, including whitespace.
AppendCodepointToUtf8String(codepoint, &str_);
} else {