Skip to content

Commit 1feecbd

Browse files
sokcevicGLUCI
authored andcommitted
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 <[email protected]> Tested-by: Josip Sokcevic <[email protected]> Commit-Queue: Josip Sokcevic <[email protected]>
1 parent 616e314 commit 1feecbd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

subcmds/branches.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ def _ProcessResults(_pool, _output, results):
167167
else:
168168
published = " "
169169

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("%", "%%"))
171174
out.write(" |")
172175

173176
_RelPath = lambda p: p.RelPath(local=opt.this_manifest_only)

0 commit comments

Comments
 (0)