mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-04 22:40:29 +03:00
add strict, tested validation of Android/F-Droid package names
Android has stricter rules than Java for Package Names, but anything the Python regex thinks is valid must be valid according to Java's rules too. https://developer.android.com/studio/build/application-id
This commit is contained in:
parent
3ab66efcfe
commit
9d12b1dc61
7 changed files with 329 additions and 14 deletions
32
tests/valid-package-names/test.py
Executable file
32
tests/valid-package-names/test.py
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def test(packageName):
|
||||
m = ANDROID_APPLICATION_ID_REGEX.match(packageName.strip())
|
||||
return m is not None
|
||||
|
||||
|
||||
ANDROID_APPLICATION_ID_REGEX = re.compile(r'''(?:^[a-z_]+(?:\d*[a-zA-Z_]*)*)(?:\.[a-z_]+(?:\d*[a-zA-Z_]*)*)*$''')
|
||||
valid = 0
|
||||
invalid = 0
|
||||
|
||||
test('org.fdroid.fdroid')
|
||||
with open('valid.txt', encoding="utf-8") as fp:
|
||||
for packageName in fp:
|
||||
packageName = packageName.strip()
|
||||
if not test(packageName):
|
||||
valid += 1
|
||||
# print('should be valid:', packageName)
|
||||
|
||||
with open('invalid.txt', encoding="utf-8") as fp:
|
||||
for packageName in fp:
|
||||
packageName = packageName.strip()
|
||||
if test(packageName):
|
||||
invalid += 1
|
||||
print('should be not valid: "' + packageName + '"')
|
||||
|
||||
|
||||
print(valid, 'Java thinks is valid, but the Android regex does not')
|
||||
print(invalid, 'invalid mistakes')
|
||||
Loading…
Add table
Add a link
Reference in a new issue