fromupstream: use more strict regular expression
Use '^' (start of the string) and '$' (end of the string) to prevent
from matching inline BUG= and TEST=.
BUG=None
TEST=1. git commit --allow-empty -F - <<EOD
Test if inline BUG=this is not a bug ID.
Test if inline TEST=this is not a test.
BUG=1234
BUG=5678
TEST=real test
EOD
2. fromupstream.py -r -d pw://11123203
3. fromupstream.py -r -d linux://d85f6b93a76e
4. fromupstream.py -r -d git://mark/for-next/96ed76983307
5. fromupstream.py -r -d https://cros#master/eb8e661
Change-Id: I9de6855f6faf63defa503a9041d653bf529e3767
Signed-off-by: Tzung-Bi Shih <tzungbi@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/1780430
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/contrib/fromupstream.py b/contrib/fromupstream.py
index 6a968aa..26eb400 100755
--- a/contrib/fromupstream.py
+++ b/contrib/fromupstream.py
@@ -322,11 +322,11 @@
if changeid_match:
args['changeid'] = changeid_match.group(1)
- bugs = re.findall('BUG=(.*)$', old_commit_message, re.MULTILINE)
+ bugs = re.findall('^BUG=(.*)$', old_commit_message, re.MULTILINE)
if args['bug'] is None and bugs:
args['bug'] = '\nBUG='.join(bugs)
- tests = re.findall('TEST=(.*)$', old_commit_message, re.MULTILINE)
+ tests = re.findall('^TEST=(.*)$', old_commit_message, re.MULTILINE)
if args['test'] is None and tests:
args['test'] = '\nTEST='.join(tests)
# TODO: deal with multiline BUG/TEST better
@@ -339,11 +339,11 @@
pprint.pprint(args)
re_matches = (
- (re.compile(r'pw://(([^/]+)/)?(\d+)'), _match_patchwork),
- (re.compile(r'linux://([0-9a-f]+)'), _match_linux),
- (re.compile(r'(from)?git://([^/\#]+)/([^#]+)/([0-9a-f]+)$'),
+ (re.compile(r'^pw://(([^/]+)/)?(\d+)'), _match_patchwork),
+ (re.compile(r'^linux://([0-9a-f]+)'), _match_linux),
+ (re.compile(r'^(from)?git://([^/\#]+)/([^#]+)/([0-9a-f]+)$'),
_match_fromgit),
- (re.compile(r'((git|https)://.+)#(.+)/([0-9a-f]+)$'), _match_gitfetch),
+ (re.compile(r'^((git|https)://.+)#(.+)/([0-9a-f]+)$'), _match_gitfetch),
)
for location in args['locations']: