diff options
author | Josip Sokcevic <sokcevic@google.com> | 2024-11-22 20:11:56 +0000 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-12-03 19:02:20 +0000 |
commit | 1feecbd91eac1b4a30e74f5356b61607d13ce89f (patch) | |
tree | 603b9eb7f19ba01801a194a4d9e8f1fb3fcb641f | |
parent | 616e314902b0234cee1cce13bed7d9ef44ce0b6c (diff) | |
download | git-repo-1feecbd91eac1b4a30e74f5356b61607d13ce89f.tar.gz |
branches: Escape percent signs in branch names
If a branch name contains a percent sign, it will be interpreted as a placeholder and color.py will fail to format it.
To avoid this, escape the percent signs prior to calling Coloring
method.
Bug: b/379090488
Change-Id: Id019c776bbf8cbed5c101f2773606f1d32c9e057
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/443801
Reviewed-by: Scott Lee <ddoman@google.com>
Tested-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
-rw-r--r-- | subcmds/branches.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/subcmds/branches.py b/subcmds/branches.py index 08c6389c..b7a45b4a 100644 --- a/subcmds/branches.py +++ b/subcmds/branches.py | |||
@@ -167,7 +167,10 @@ is shown, then the branch appears in all projects. | |||
167 | else: | 167 | else: |
168 | published = " " | 168 | published = " " |
169 | 169 | ||
170 | hdr("%c%c %-*s" % (current, published, width, name)) | 170 | # A branch name can contain a percent sign, so we need to escape it. |
171 | # Escape after f-string formatting to properly account for leading | ||
172 | # spaces. | ||
173 | hdr(f"{current}{published} {name:{width}}".replace("%", "%%")) | ||
171 | out.write(" |") | 174 | out.write(" |") |
172 | 175 | ||
173 | _RelPath = lambda p: p.RelPath(local=opt.this_manifest_only) | 176 | _RelPath = lambda p: p.RelPath(local=opt.this_manifest_only) |