From ea8a7f54d5d39461da355203ed90fc9309584855 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 22 Dec 2015 20:18:19 +0200 Subject: [PATCH] Do not escape '-' and '_' in url path and query args --- args_test.go | 2 +- bytesconv.go | 2 +- uri.go | 2 +- uri_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/args_test.go b/args_test.go index 0fe7be8..f994217 100644 --- a/args_test.go +++ b/args_test.go @@ -10,7 +10,7 @@ import ( func TestArgsEscape(t *testing.T) { testArgsEscape(t, "foo", "bar", "foo=bar") testArgsEscape(t, "f.o,1:2/4", "~`!@#$%^&*()_-=+\\|/[]{};:'\"<>,./?", - "f.o,1:2/4=%7E%60%21%40%23%24%25%5E%26%2A%28%29%5F%2D%3D%2B%5C%7C/%5B%5D%7B%7D%3B:%27%22%3C%3E,./%3F") + "f.o,1:2/4=%7E%60%21%40%23%24%25%5E%26%2A%28%29_-%3D%2B%5C%7C/%5B%5D%7B%7D%3B:%27%22%3C%3E,./%3F") } func testArgsEscape(t *testing.T, k, v, expectedS string) { diff --git a/bytesconv.go b/bytesconv.go index 8237dbe..f203b29 100644 --- a/bytesconv.go +++ b/bytesconv.go @@ -312,7 +312,7 @@ func unsafeBytesToStr(b []byte) string { func appendQuotedArg(dst, v []byte) []byte { for _, c := range v { if c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || - c == '/' || c == '.' || c == ',' || c == ':' { + c == '/' || c == '.' || c == ',' || c == ':' || c == '-' || c == '_' { dst = append(dst, c) } else { dst = append(dst, '%', hexCharUpper(c>>4), hexCharUpper(c&15)) diff --git a/uri.go b/uri.go index 9bd9ed0..a94dd54 100644 --- a/uri.go +++ b/uri.go @@ -438,7 +438,7 @@ func (x *URI) parseQueryArgs() { func appendQuotedPath(dst, v []byte) []byte { for _, c := range v { if c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || - c == '/' || c == '.' || c == ',' || c == '=' || c == ':' || c == '&' || c == '~' { + c == '/' || c == '.' || c == ',' || c == '=' || c == ':' || c == '&' || c == '~' || c == '-' || c == '_' { dst = append(dst, c) } else { dst = append(dst, '%', hexCharUpper(c>>4), hexCharUpper(c&15)) diff --git a/uri_test.go b/uri_test.go index 13ef871..5362910 100644 --- a/uri_test.go +++ b/uri_test.go @@ -7,7 +7,7 @@ import ( func TestURIPathEscape(t *testing.T) { testURIPathEscape(t, "/foo/bar", "/foo/bar") - testURIPathEscape(t, "/foo=b:ar,b.c&q", "/foo=b:ar,b.c&q") + testURIPathEscape(t, "/f_o-o=b:ar,b.c&q", "/f_o-o=b:ar,b.c&q") testURIPathEscape(t, "/aa?bb.ั‚ะตัั‚~qq", "/aa%3Fbb.%D1%82%D0%B5%D1%81%D1%82~qq") }