如何逃脱网址托管?

I have the following URL I'm trying to process:

http://shitenonions%2elibsyn%2ecom/rss

When I try to create a url out of it in Go, I get the following error:

panic: parse http://shitenonions%2elibsyn%2ecom/rss: hexadecimal escape in host

How can I fix this URL so it can be parsed correctly? I have a large set of URLs and several of them have this problem.

I thought about URL decoding it, but I'm worried that if I do that, it might be incorrect to url decode items besides the host name.

You can use url.QueryUnescape to decode entities %hh back to the characters:

package main

import (
  "fmt"
  "net/url"
  "strings"
)

func fixHost(link string) string {
  if strings.HasPrefix(link, "http://") {
    p := strings.Index(link[7:], "/")
    if -1 != p {
      host, _ := url.QueryUnescape(link[7:7+p])
      return "http://" + host + link[7+p:]
    }
  }
  return link
}

func main() {
  fmt.Println(fixHost("http://shitenonions%2elibsyn%2ecom/rss"))
}