diff --git a/project.py b/project.py index 9f79030..b7ed6f3 100644 --- a/project.py +++ b/project.py @@ -996,6 +996,13 @@ class Project(object): if not branch.remote.review: raise GitError('remote %s has no review url' % branch.remote.name) + # Basic validity check on label syntax. + for label in labels: + if not re.match(r'^.+[+-][0-9]+$', label): + raise UploadError( + f'invalid label syntax "{label}": labels use forms like ' + 'CodeReview+1 or Verified-1') + if dest_branch is None: dest_branch = self.dest_branch if dest_branch is None: @@ -1031,6 +1038,7 @@ class Project(object): if auto_topic: opts += ['topic=' + branch.name] opts += ['t=%s' % p for p in hashtags] + # NB: No need to encode labels as they've been validated above. opts += ['l=%s' % p for p in labels] opts += ['r=%s' % p for p in people[0]] diff --git a/subcmds/upload.py b/subcmds/upload.py index ef3d8e9..20b8fe5 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py @@ -421,12 +421,6 @@ Gerrit Code Review: https://www.gerritcodereview.com/ labels = set(_ExpandCommaList(branch.project.config.GetString(key))) for label in opt.labels: labels.update(_ExpandCommaList(label)) - # Basic sanity check on label syntax. - for label in labels: - if not re.match(r'^.+[+-][0-9]+$', label): - print('repo: error: invalid label syntax "%s": labels use forms ' - 'like CodeReview+1 or Verified-1' % (label,), file=sys.stderr) - sys.exit(1) # Handle e-mail notifications. if opt.notify is False: