this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

๐Ÿ› Escape path segments when registering handlers

+8 -3
+8 -3
main.go
··· 4 4 "encoding/json" 5 5 "fmt" 6 6 "net/http" 7 + "net/url" 7 8 "os" 8 9 "path/filepath" 9 10 "sort" ··· 82 83 ch: templ.Handler(pages.Layout(page, navigation, sites, translations.language)), 83 84 } 84 85 85 - server.Handle(fmt.Sprintf("/%s", path), translator) 86 + escapedSegments := []string{} 87 + for _, segment := range strings.Split(path, "/") { 88 + escapedSegments = append(escapedSegments, url.PathEscape(segment)) 89 + } 90 + server.Handle(fmt.Sprintf("/%s", strings.Join(escapedSegments, "/")), translator) 86 91 registeredPaths = append(registeredPaths, path) 87 92 } 88 93 89 94 redirect := func(from, to string) { 90 95 if !strings.HasPrefix(to, "https://") && !strings.HasPrefix(to, "mailto:") && !strings.HasPrefix(to, "http://") { 91 - to = fmt.Sprintf("/%s", to) 96 + to = fmt.Sprintf("/%s", url.PathEscape(to)) 92 97 } 93 98 // fmt.Printf("[%s] Registering redirect /%s -> %s\n", locale, from, to) 94 - server.Handle(fmt.Sprintf("/%s", from), http.RedirectHandler(to, http.StatusSeeOther)) 99 + server.Handle(fmt.Sprintf("/%s", url.PathEscape(from)), http.RedirectHandler(to, http.StatusSeeOther)) 95 100 } 96 101 97 102 handlePage("", pages.Index(db, translations.language))