Merge "Fixing edge cases that @string references passed in path parts."

This commit is contained in:
Brandon Liu
2022-11-04 18:06:01 +00:00
committed by Android (Google) Code Review
2 changed files with 24 additions and 2 deletions

View File

@@ -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)

View File

@@ -1408,5 +1408,24 @@ TEST_F(ManifestFixerTest, IntentFilterPathMustStartWithLeadingSlashOnDeepLinks)
</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