diff options
author | Gergely Nagy <forgejo@gergo.csillger.hu> | 2024-03-20 22:41:20 +0100 |
---|---|---|
committer | Gergely Nagy <forgejo@gergo.csillger.hu> | 2024-03-20 22:41:20 +0100 |
commit | 8433f3aa09cad7e245025545912667e0ec1cc0c6 (patch) | |
tree | 3197858d3a4f397129b91a1f3622fd8a74efe355 /routers | |
parent | Merge pull request '[CI] simplify running end-to-end tests while building a r... (diff) | |
download | forgejo-8433f3aa09cad7e245025545912667e0ec1cc0c6.tar.xz forgejo-8433f3aa09cad7e245025545912667e0ec1cc0c6.zip |
Fix repo badges when the label or text contains dashes
shields.io uses dashes to separate parts of the badge it needs to
return. If our label or text parts contain dashes, we need to encode
those for shields.io to recognise what we want it to do, and to have the
correct text on the badge, too.
Fortunately, this is as simple as replacing all dashes with double
dashes in both the label and the text parts. We do not need to do the
same for the color, because that part is not user controlled.
This fixes the badges for cases when a workflow name includes dashes, or
when a release's tag name does.
Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/badges/badges.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/routers/web/repo/badges/badges.go b/routers/web/repo/badges/badges.go index 7f4549d606..ed40e982a1 100644 --- a/routers/web/repo/badges/badges.go +++ b/routers/web/repo/badges/badges.go @@ -18,8 +18,8 @@ import ( func getBadgeURL(ctx *context_module.Context, label, text, color string) string { sb := &strings.Builder{} _ = setting.Badges.GeneratorURLTemplateTemplate.Execute(sb, map[string]string{ - "label": url.PathEscape(label), - "text": url.PathEscape(text), + "label": url.PathEscape(strings.ReplaceAll(label, "-", "--")), + "text": url.PathEscape(strings.ReplaceAll(text, "-", "--")), "color": url.PathEscape(color), }) |