Ask coding questions

← Back to all posts
Go not handling paths with encoded values in it
Baconman321 (1097)

I made a special handler for certain links. Those links are encoded using net/http's QueryEscape.

What I'm having trouble with though, is that my program seems to not handle paths with special characters.

The code that is relevant for an MRE:

var articlesSlice []struct{
  Title, URL string
file, _ := ioutil.ReadFile("public/articleLinks.json")
json.Unmarshal(file, &articlesSlice)
for _, article := range articlesSlice {
  //Yes, handleArticle IS defined (somewhere else in the code)
  http.HandleFunc("/docs/" + article.URL, handleArticle)

The JSON file it is pulling the links from looks like this:

    "Title": "Welcome (README)",
    "URL": "welcome+%28readme%29"
    "Title": "test",
    "URL": "test"
    "Title": "test 2",
    "URL": "test+2"
    "Title": "whelp()",
    "URL": "whelp%28%29"

Go doesn't seem to want to handle the paths with special characters in them.

/docs/test is the only one that works.

The rest give a 404.