From a35bf78caae3eb1bd4b35c2e7988890d01b6f4c8 Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Thu, 3 Nov 2022 19:04:31 +0000 Subject: [PATCH] Fixing edge cases that @string references passed in path parts. Bug: b/241114745 Test: Added and verified affected atests pass Change-Id: Ia7048222bf91aa3ce02e090789e9af05bbed97e1 --- tools/aapt2/link/ManifestFixer.cpp | 7 +++++-- tools/aapt2/link/ManifestFixer_test.cpp | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp index df09e47aa9469..d0850b800e4f9 100644 --- a/tools/aapt2/link/ManifestFixer.cpp +++ b/tools/aapt2/link/ManifestFixer.cpp @@ -69,7 +69,9 @@ static bool VerifyDeeplinkPathAttribute(xml::Element* data_el, android::SourcePa StringPiece attr_value = attr->value; const char* startChar = attr_value.begin(); if (attr_name == "pathPattern") { - if (*startChar == '/' || *startChar == '.' || *startChar == '*') { + // pathPattern starts with '.' or '*' does not need leading slash. + // Reference starts with @ does not need leading slash. + if (*startChar == '/' || *startChar == '.' || *startChar == '*' || *startChar == '@') { return true; } else { diag->Error(android::DiagMessage(data_el->line_number) @@ -80,7 +82,8 @@ static bool VerifyDeeplinkPathAttribute(xml::Element* data_el, android::SourcePa return false; } } else { - if (*startChar == '/') { + // Reference starts with @ does not need leading slash. + if (*startChar == '/' || *startChar == '@') { return true; } else { diag->Error(android::DiagMessage(data_el->line_number) diff --git a/tools/aapt2/link/ManifestFixer_test.cpp b/tools/aapt2/link/ManifestFixer_test.cpp index cec9a1a5917e3..8d1a647b494d8 100644 --- a/tools/aapt2/link/ManifestFixer_test.cpp +++ b/tools/aapt2/link/ManifestFixer_test.cpp @@ -1408,5 +1408,24 @@ TEST_F(ManifestFixerTest, IntentFilterPathMustStartWithLeadingSlashOnDeepLinks) )"; EXPECT_THAT(Verify(input), NotNull()); + + // DeepLink with string reference as a path. + input = R"( + + + + + + + + + + + + )"; + EXPECT_THAT(Verify(input), NotNull()); } } // namespace aapt