From a7dc6ca4b176cc4a918a73ffd0ab7df92011fdbb Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 25 Apr 2019 11:43:52 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/net/url/url.go | 4 ++-- src/net/url/url_test.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/net/url/url.go b/src/net/url/url.go index b7e8beec75..5f40555bdc 100644 --- a/src/net/url/url.go +++ b/src/net/url/url.go @@ -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) } diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go index c5fc90d515..27e132b1cd 100644 --- a/src/net/url/url_test.go +++ b/src/net/url/url_test.go @@ -929,6 +929,11 @@ var pathEscapeTests = []EscapeTest{ "abc+def", nil, }, + { + "a/b", + "a%2Fb", + nil, + }, { "one two", "one%20two", -- 2.50.0