Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
golang url.PathUnescape无法在%%_Go_Url - Fatal编程技术网

golang url.PathUnescape无法在%%

golang url.PathUnescape无法在%%,go,url,Go,Url,我使用golang url.PathUnescape函数来显示url,但它不能在%%中工作 我收到一个请求,其url为/search/?ptp=1&q=%27%22&%%3cacx%3e%3cscript%20%3emcyv9834%3c/script%3e&t=bao。 当我使用golang url.PathUnescape函数来取消浏览url时,它有一个错误是无效的url转义%%3。为什么? package main import ( "net/url" "fmt" ) fu

我使用golang url.PathUnescape函数来显示url,但它不能在%%中工作

我收到一个请求,其url为/search/?ptp=1&q=%27%22&%%3cacx%3e%3cscript%20%3emcyv9834%3c/script%3e&t=bao。 当我使用golang url.PathUnescape函数来取消浏览url时,它有一个错误是无效的url转义%%3。为什么?

package main
import (
    "net/url"
    "fmt"
)
func main() {
    str := `/search/?ptp=1&q=%27%22&%%3Cacx%3E%3CScRiPt%20%3EmCyV9834%3C/ScRiPt%3E&t=bao`
    a, b := url.PathUnescape(str)
    fmt.Println(a, b)
}
源url为/search/?ptp=1&q='&%mCyV9834&t=bao

但有一个错误是无效的URL转义%%3。为什么?

package main
import (
    "net/url"
    "fmt"
)
func main() {
    str := `/search/?ptp=1&q=%27%22&%%3Cacx%3E%3CScRiPt%20%3EmCyV9834%3C/ScRiPt%3E&t=bao`
    a, b := url.PathUnescape(str)
    fmt.Println(a, b)
}
因为%%3在URL路径中不是有效的百分比编码


如果需要处理格式错误的URL,则必须自己实现。或者修复上游。

Python url解析是正确的。Golang url库不能解析%%%,所以我写了一个函数来处理这个问题。