Skip to content

Commit 2a314d3

Browse files
authored
fix: Ignore case in validatePackageName (#1660)
* Ignore case in validatePackageName Currently `validatePackageName` fails for package names containing uppercase letters. A message like this is shown during pod install: ``` warn Invalid application's package name "com.lugg.ReactNativeConfig" in 'AndroidManifest.xml'. Read guidelines for setting the package name here: https://developer.android.com/studio/build/application-id warn Invalid application's package name "com.BV.LinearGradient" in 'AndroidManifest.xml'. Read guidelines for setting the package name here: https://developer.android.com/studio/build/application-id warn Invalid application's package name "com.lugg.ReactNativeConfig" in 'AndroidManifest.xml'. Read guidelines for setting the package name here: https://developer.android.com/studio/build/application-id warn Invalid application's package name "com.BV.LinearGradient" in 'AndroidManifest.xml'. Read guidelines for setting the package name here: https://developer.android.com/studio/build/application-id ``` However both the package name (https://developer.android.com/guide/topics/manifest/manifest-element.html#package) and the application id (https://developer.android.com/studio/build/application-id) are allowed to contain upper case letters. This change adds the "i" flag to the regex to ignore case when validating package name. Related issue: facebook/react-native#34247 * Add tests for validatePackageName
1 parent aa8299b commit 2a314d3

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*/
8+
9+
import {validatePackageName} from '../getAndroidProject';
10+
11+
describe('android::getAndroidProject', () => {
12+
const expectedResults = {
13+
'com.app': true,
14+
'com.example.app': true,
15+
'com.my_app': true,
16+
'org.my_app3': true,
17+
'com.App': true,
18+
'com.Example.APP1': true,
19+
'COM.EXAMPLE.APP': true,
20+
'': false,
21+
com: false,
22+
'com.3example.app': false,
23+
'com.my_app*': false,
24+
'org.my-app3': false,
25+
'com.App ': false,
26+
'com.Example.APP#1': false,
27+
};
28+
29+
Object.keys(expectedResults).forEach((packageName) => {
30+
it(`should validate package name "${packageName}" correctly`, () => {
31+
expect(validatePackageName(packageName)).toBe(
32+
expectedResults[packageName],
33+
);
34+
});
35+
});
36+
});

packages/cli-platform-android/src/config/getAndroidProject.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ export function getPackageName(manifestPath: string) {
4747
}
4848

4949
// Validates that the package name is correct
50-
function validatePackageName(packageName: string) {
51-
return /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/.test(packageName);
50+
export function validatePackageName(packageName: string) {
51+
return /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/i.test(packageName);
5252
}

0 commit comments

Comments
 (0)