Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions blog/blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (b *Blog) getPostByParams(year int, month int, day int, slug string) (*Post
func (b *Blog) getPostsByTag(c *gin.Context) ([]Post, error) {
var posts []Post
var tag Tag
name := c.Param("name")
name := strings.TrimPrefix(c.Param("name"), "/")
if err := (*b.db).Where("name = ?", name).First(&tag).Error; err != nil {
return nil, errors.New("No tag named " + name)
}
Expand Down Expand Up @@ -306,7 +306,7 @@ func (b *Blog) Post(c *gin.Context) {

// Tag lists all posts with a given tag
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 {
Comment on lines 308 to 311
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.
c.HTML(http.StatusNotFound, "error.html", gin.H{
Expand Down
2 changes: 1 addition & 1 deletion blog/blog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestBlogWorkflow(t *testing.T) {

//html requests
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)
Comment on lines 60 to 62
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.
router.GET("/tags", b.Tags)
router.GET("/", b.Home)
Expand Down
2 changes: 1 addition & 1 deletion goblog.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (g goblog) addRoutes() {
// lets posts work with our without the word posts in front
g.router.GET("/:yyyy/:mm/:dd/:slug", g._blog.Post)
g.router.GET("/admin/posts/:yyyy/:mm/:dd/:slug", g._admin.Post)
g.router.GET("/tag/:name", g._blog.Tag)
g.router.GET("/tag/*name", g._blog.Tag)
g.router.GET("/logout", g._blog.Logout)

//todo: register a template mapping to a "page type"
Expand Down
2 changes: 1 addition & 1 deletion templates/post-admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2 class="text-left" contenteditable="true" id="title" onfocusout="updatePost({
<p class="blog-post-meta text-left">Posted on {{ .post.CreatedAt.Format "Jan 02, 2006 15:04:05 UTC" }}. Last Edited on {{ .post.UpdatedAt.Format "Jan 02, 2006 15:04:05 UTC" }} [ <a href="#" onclick="return deletePost($post.ID)">Delete</a>] </p>
<p class="tags text-left">
{{range .post.Tags}}
<a href="/tag/{{.Name}}">#{{.Name}}</a>
<a href="{{ .Permalink }}">#{{.Name}}</a>
{{end}}
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2 class="text-left"><a href="{{ .post.Permalink }}">{{ .post.Title }}</a></h2>
<p class="blog-post-meta text-left">Posted on {{ .post.CreatedAt.Format "Jan 02, 2006 15:04:05 UTC" }}. Last Edited on {{ .post.UpdatedAt.Format "Jan 02, 2006 15:04:05 UTC" }} </p>
<p class="tags text-left">
{{range .post.Tags}}
<a href="/tag/{{.Name}}">#{{.Name}}</a>
<a href="{{ .Permalink }}">#{{.Name}}</a>
{{end}}
</p>
{{ if .is_admin }}
Expand Down
Loading