summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-06-02 16:32:37 -0700
committerAdam Lesinski <adamlesinski@google.com>2017-06-06 20:02:38 +0000
commitb9f0548341f98a64a87fa35ef5f58d1daf973ca7 (patch)
treeb18439dee3ec04c180e2934a0d5d6c574ee37be4
parent63c5c9462a0175143791d7a5491a67a1a645cab4 (diff)
AAPT2: Do not interpret %n as a format specifier in string resources
%n is a special value marking a platform independent newline and is not to be considered a format argument. Bug: 37132275 Test: make aapt2_tests Change-Id: I806521e44afe20004344dee9f18ecee6cc7086ea
-rw-r--r--tools/aapt2/ResourceParser_test.cpp5
-rw-r--r--tools/aapt2/util/Util.cpp2
2 files changed, 6 insertions, 1 deletions
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp
index 5352ca8679b3..c6382b177f42 100644
--- a/tools/aapt2/ResourceParser_test.cpp
+++ b/tools/aapt2/ResourceParser_test.cpp
@@ -843,4 +843,9 @@ TEST_F(ResourceParserTest, ParseElementWithNoValue) {
EXPECT_THAT(*str->value, Eq(""));
}
+TEST_F(ResourceParserTest, ParsePlatformIndependentNewline) {
+ std::string input = R"(<string name="foo">%1$s %n %2$s</string>)";
+ ASSERT_TRUE(TestParse(input));
+}
+
} // namespace aapt
diff --git a/tools/aapt2/util/Util.cpp b/tools/aapt2/util/Util.cpp
index cf2232254ec4..28e952e25a67 100644
--- a/tools/aapt2/util/Util.cpp
+++ b/tools/aapt2/util/Util.cpp
@@ -203,7 +203,7 @@ bool VerifyJavaStringFormat(const StringPiece& str) {
if (*c == '%' && c + 1 < end) {
c++;
- if (*c == '%') {
+ if (*c == '%' || *c == 'n') {
c++;
continue;
}