Skip to content

Commit

Permalink
net/url: document, test that PathEscape escapes / to %2F
Browse files Browse the repository at this point in the history
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: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
rsc committed Apr 26, 2019
1 parent 216797b commit a7dc6ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/net/url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ func QueryEscape(s string) string {
return escape(s, encodeQueryComponent)
}

// PathEscape escapes the string so it can be safely placed
// inside a URL path segment.
// PathEscape escapes the string so it can be safely placed inside a URL path segment,
// replacing special characters (including /) with %XX sequences as needed.
func PathEscape(s string) string {
return escape(s, encodePathSegment)
}
Expand Down
5 changes: 5 additions & 0 deletions src/net/url/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,11 @@ var pathEscapeTests = []EscapeTest{
"abc+def",
nil,
},
{
"a/b",
"a%2Fb",
nil,
},
{
"one two",
"one%20two",
Expand Down

0 comments on commit a7dc6ca

Please sign in to comment.