Skip to content

Fix tags with slash in name breaking routes#475

Merged
compscidr merged 1 commit intomainfrom
fix/tags-with-slash
Mar 3, 2026
Merged

Fix tags with slash in name breaking routes#475
compscidr merged 1 commit intomainfrom
fix/tags-with-slash

Conversation

@compscidr
Copy link
Collaborator

@compscidr compscidr commented Mar 3, 2026

Fixes #55

Summary

  • Tags containing / (e.g. c/c++) broke because Gin's :name route parameter stops capturing at the first /, so /tag/c/c++ only matched c
  • Switch to *name wildcard parameter which captures the full path including slashes
  • Trim the leading / that wildcard params include from the captured value
  • Update post.html and post-admin.html templates to use .Permalink() instead of hardcoding /tag/{{.Name}}

Test plan

  • go test ./... passes
  • Navigate to a tag page with / in the name (e.g. c/c++) — should load correctly
  • Tag links on post pages still work for regular tags
  • /tags index page links still work

🤖 Generated with Claude Code

Tags containing "/" (e.g. "c/c++") broke because Gin's :name parameter
stops capturing at the first slash. Switch to *name wildcard parameter
which captures the full path including slashes, and trim the leading "/"
that wildcard params include. Also update templates to use .Permalink()
instead of hardcoding /tag/{{.Name}}.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 3, 2026 05:24
@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.92%. Comparing base (c5bb0b6) to head (3f7dc62).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #475   +/-   ##
=======================================
  Coverage   41.92%   41.92%           
=======================================
  Files           6        6           
  Lines        1016     1016           
=======================================
  Hits          426      426           
  Misses        561      561           
  Partials       29       29           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes tag pages and tag links for tag names containing / by switching Gin’s tag route to a wildcard capture and normalizing the captured value; updates templates to rely on tag permalinks rather than hardcoded tag URLs.

Changes:

  • Change tag route from /tag/:name to /tag/*name to support slashes in tag names.
  • Trim the leading / included by Gin wildcard params before querying tags.
  • Update post templates to use Tag.Permalink() (via {{ .Permalink }}) for tag links.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
templates/post.html Uses tag permalink for tag links so names with / generate valid URLs.
templates/post-admin.html Same tag-link update for the admin post view.
goblog.go Switches the main server’s tag route to a wildcard parameter.
blog/blog_test.go Updates test router to register the wildcard tag route.
blog/blog.go Normalizes wildcard-captured tag names by trimming the leading /.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 60 to 62
router.GET("/posts/:yyyy/:mm/:dd/:slug", b.Post)
router.GET("/tag/:name", b.Tag)
router.GET("/tag/*name", b.Tag)
router.GET("/posts", b.Posts)
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated route is intended to fix tags containing '/'. The test suite currently only exercises /tag/test and doesn’t include a regression test for a tag name with a slash (e.g. /tag/c/c++). Add a test that creates a tag with a slash in its name and asserts the handler returns 200 for that URL, so this bug can’t reappear unnoticed.

Copilot uses AI. Check for mistakes.
Comment on lines 308 to 311
func (b *Blog) Tag(c *gin.Context) {
tag := c.Param("name")
tag := strings.TrimPrefix(c.Param("name"), "/")
posts, err := b.getPostsByTag(c)
if err != nil {
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag() now normalizes the wildcard param into tag, but getPostsByTag(c) re-reads c.Param("name") and repeats the normalization. To avoid drift (and double work), consider extracting the normalized tag name once (e.g., helper tagNameFromContext or pass tag into getPostsByTag) and use that value consistently.

Copilot uses AI. Check for mistakes.
@compscidr compscidr merged commit 5901b46 into main Mar 3, 2026
8 of 9 checks passed
@compscidr compscidr deleted the fix/tags-with-slash branch March 3, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tags with / break

2 participants