mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-04 06:30:27 +03:00 
			
		
		
		
	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
		
			
				
	
	
		
			32 lines
		
	
	
	
		
			885 B
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
	
		
			885 B
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
#!/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')
 |