Commit a7dc6ca4 authored by Russ Cox's avatar Russ Cox

net/url: document, test that PathEscape escapes / to %2F

I couldn't remember and couldn't tell from the docs,
so I added a test and documented what I found.

Change-Id: Ic5d837c2d620b15d7a831823e94e70080f5e5324
Reviewed-on: https://go-review.googlesource.com/c/go/+/173948
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 216797b6
...@@ -276,8 +276,8 @@ func QueryEscape(s string) string { ...@@ -276,8 +276,8 @@ func QueryEscape(s string) string {
return escape(s, encodeQueryComponent) return escape(s, encodeQueryComponent)
} }
// PathEscape escapes the string so it can be safely placed // PathEscape escapes the string so it can be safely placed inside a URL path segment,
// inside a URL path segment. // replacing special characters (including /) with %XX sequences as needed.
func PathEscape(s string) string { func PathEscape(s string) string {
return escape(s, encodePathSegment) return escape(s, encodePathSegment)
} }
......
...@@ -929,6 +929,11 @@ var pathEscapeTests = []EscapeTest{ ...@@ -929,6 +929,11 @@ var pathEscapeTests = []EscapeTest{
"abc+def", "abc+def",
nil, nil,
}, },
{
"a/b",
"a%2Fb",
nil,
},
{ {
"one two", "one two",
"one%20two", "one%20two",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment