HTML Template may invalidate URLs encoded using url.QueryEscape

Ah ok, I see. Well in that case, I would probably go with using html.UnescapeString, not url.QueryUnescape, especially since for the above example, url.QueryUnescape won’t even turn the + back into a +.

Example:

package main

import (
	"fmt"
	"html"
	"log"
	"net/url"
)

var urlStr = "http://google.com/?q=hello+world"

func main() {
	urlEsc, err := url.QueryUnescape(urlStr)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(urlEsc) // http://google.com/?q=hello+world

	fmt.Println(html.UnescapeString(urlStr)) // http://google.com/?q=hello+world
}
2 Likes