From 3a0a145b0ec52dff88b021c5937925f25294a10f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 20 May 2022 12:52:33 -0400 Subject: [PATCH] upload: move label validation to core function This way we know we don't need to encode the labels. Change-Id: Ib83ed8f4ed05f00b9d2d06a9dd3f304e4443430e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/337518 Tested-by: Mike Frysinger Reviewed-by: LaMont Jones --- project.py | 8 ++++++++ subcmds/upload.py | 6 ------ 2 files changed, 8 insertions(+), 6 deletions(-) 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: