Fixing edge cases that @string references passed in path parts.
Bug: b/241114745
Test: Added and verified affected atests pass
Change-Id: Ia7048222bf91aa3ce02e090789e9af05bbed97e1
diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp
index df09e47..d0850b8 100644
--- a/tools/aapt2/link/ManifestFixer.cpp
+++ b/tools/aapt2/link/ManifestFixer.cpp
@@ -69,7 +69,9 @@
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 @@
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 cec9a1a..8d1a647 100644
--- a/tools/aapt2/link/ManifestFixer_test.cpp
+++ b/tools/aapt2/link/ManifestFixer_test.cpp
@@ -1408,5 +1408,24 @@
</application>
</manifest>)";
EXPECT_THAT(Verify(input), NotNull());
+
+ // DeepLink with string reference as a path.
+ input = R"(
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android">
+ <application>
+ <activity android:name=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+ <data android:scheme="http"
+ android:host="www.example.com"
+ android:path="@string/startup_uri" />
+ </intent-filter>
+ </activity>
+ </application>
+ </manifest>)";
+ EXPECT_THAT(Verify(input), NotNull());
}
} // namespace aapt