fdroid-server/fdroidserver
Hans-Christoph Steiner 06fb855a27 common: tighten up regexs when searching for version name/code and appid
This should have less of a change of matching bad things.
thanks to @stf for the report.  I ran tests comparing the original vs these
new patterns, and it was a 100% match. So at least it didn't make things
worse.

Here's the test script:
#!/usr/bin/env python3

import os
import re


old_vcsearch_g = re.compile(r'''.*[Vv]ersionCode[ =]+["']*([0-9]+)["']*''').search
old_vnsearch_g = re.compile(r'.*[Vv]ersionName *=* *(["\'])((?:(?=(\\?))\3.)*?)\1.*').search
old_psearch_g = re.compile(r'.*(packageName|applicationId) *=* *["\']([^"]+)["\'].*').search
new_vcsearch_g = re.compile(r'''.*[Vv]ersionCode\s*=?\s*["']*([0-9]+)["']*''').search
new_vnsearch_g = re.compile(r'''.*[Vv]ersionName\s*=?\s*(["'])((?:(?=(\\?))\3.)*?)\1.*''').search
new_psearch_g = re.compile(r'''.*(packageName|applicationId)\s*=*\s*["']([^"']+)["'].*''').search

old = re.compile(r'.*(packageName|applicationId) *=* *["\']([^"]+)["\'].*').search
new = re.compile(r'''.*(packageName|applicationId)\s*=*\s*["']([^"']+)["'].*''').search


for root, dirs, files in os.walk('build'):
    for f in files:
        if f.endswith('.gradle'):
            with open(os.path.join(root, f)) as fp:
                for line in fp:
                    for old, new in ((old_vcsearch_g, new_vcsearch_g),
                                     (old_vnsearch_g, new_vnsearch_g),
                                     (old_psearch_g, new_psearch_g)):
                        found_old = old(line)
                        found_new = new(line)
                        oldresult = None
                        newresult = None
                        if found_old or found_new:
                            if found_old:
                                oldresult = found_old.groups()
                                #print('OLD', oldresult)
                            if found_new:
                                newresult = found_new.groups()
                                #print('NEW', newresult)
                            if oldresult != newresult:
                                print('--------------------------------')
                                print(f, oldresult, newresult)
2018-02-22 21:15:41 +01:00
..
asynchronousfilereader Add asynchronous filereader, fix python3 lockups 2015-09-20 20:57:53 +02:00
__init__.py fix egg-link and easy_install support for Python3 2017-10-19 23:28:13 +02:00
btlog.py implement gettext localization 2017-09-15 11:39:00 +02:00
build.py make is_apk_and_debuggable() default to using androguard before aapt 2018-02-22 15:08:53 +01:00
checkupdates.py wiki: move checkupdates wiki log to separate function 2018-01-22 13:49:10 +01:00
common.py common: tighten up regexs when searching for version name/code and appid 2018-02-22 21:15:41 +01:00
dscanner.py English source string corrections 2017-09-16 13:19:38 +02:00
exception.py checkupdates: don't fail when we can't init submodules 2017-12-04 16:30:37 +01:00
gpgsign.py implement gettext localization 2017-09-15 11:39:00 +02:00
import.py import: fix crash when importing from local git repo 2018-02-12 12:05:27 +01:00
index.py Reorder the gitlab mirrors so GitLab Pages comes before "raw". 2018-01-18 08:02:07 +11:00
init.py init: do not try to find aapt if androguard is available 2018-02-22 13:38:02 +01:00
install.py fix string formats that are ambiguous for translators 2017-09-16 13:19:38 +02:00
lint.py lint: check srclibs has name and @ in it 2018-01-31 13:33:36 +01:00
metadata.py metadata: write values of TYPE_INT fields 2018-02-11 09:51:53 +03:00
mirror.py mirror: fix syntax error on Python 3.4 2017-11-30 14:03:04 +01:00
net.py Support ETag when downloading repository index 2017-05-02 15:37:02 -03:00
nightly.py nightly: support arbitrary keystore files for setup 2017-12-28 23:07:26 +01:00
publish.py add common.sign_apk() for nighly as test for using in publish 2017-12-04 22:52:41 +01:00
readmeta.py all: make newer pycodestyle happy 2016-11-15 20:55:06 +00:00
rewritemeta.py fix string formats that are ambiguous for translators 2017-09-16 13:19:38 +02:00
scanner.py scanner: allow running without versionCode and as API 2018-01-26 10:18:41 +01:00
server.py wiki: log server start/stop times and command line 2018-01-22 13:49:10 +01:00
signatures.py HTTP, HTTPS 2017-10-22 06:43:18 +00:00
signindex.py implement gettext localization 2017-09-15 11:39:00 +02:00
stats.py implement gettext localization 2017-09-15 11:39:00 +02:00
tail.py include class like UNIX `tail -f` for displaying logs 2017-05-23 20:04:08 +02:00
update.py update: switch to improved androguard detection 2018-02-22 15:08:54 +01:00
verify.py fix string formats that are ambiguous for translators 2017-09-16 13:19:38 +02:00
vmtools.py vmtools: use standard imports: os.remove() 2018-01-26 10:18:42 +01:00