hello everybody.
I was trying to parse an url that contins in its “path” field the following string:
Segment%%2815197306101420000%29.ts
and I get this error:
invalid URL escape "%%2"
I looked around to see if the an URL could contain “%%” or not and I believe it could, please tell me if I am wrong on this point.
if the string “%%2” is acceptable in an URL could there be something wrong in the net/url parsing code?
lutzhorn
(Lutz Horn)
February 27, 2018, 1:48pm
2
Is the actual name of this file Segment%(15197306101420000).ts
?
What code do you use?
adriel
(adriel)
February 27, 2018, 2:16pm
3
Use QueryEscape to escape the string, so it can be safely placed inside a URL query before you parse the url.
https://golang.org/pkg/net/url/#QueryEscape
func main() {
s := "http://test.com/Segment%%2815197306101420000%29.ts" // assuming that url contains '%%2'
qs := url.QueryEscape(s)
u, err := url.Parse(qs)
if err != nil {
panic(err)
}
fmt.Println("scheme: ",u.Path)
}
1 Like
lutzhorn
(Lutz Horn)
February 27, 2018, 2:28pm
4
The output of this code is
scheme: http://test.com/Segment%%2815197306101420000%29.ts
Is this what is requested or shall the %28
and %29
be decoded to (
and )
?
1 Like
adriel
(adriel)
February 27, 2018, 2:40pm
5
It mentioned, if there’s something wrong in the net/url parsing code. so the code example shows that there’s nothing wrong with net/url, just add some implementation query escape before parsing url.
1 Like
I checked with my coworkers and as you mentioned %28 should be translated as an open bracket.
It seems that some user agents don’t cope well with those urls.
Thanks for the help
Yeah that’s right %28 should be understood as a bracket.
Nothing wrong with the net/url code.
Thank you
system
(system)
Closed
May 29, 2018, 12:55pm
9
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.