Skip to content

Commit c5db558

Browse files
authored
Merge pull request #11 from erraggy/master
chore(deps): removes purell from dependancies
2 parents 238d8d0 + b112df9 commit c5db558

File tree

4 files changed

+67
-17
lines changed

4 files changed

+67
-17
lines changed

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
module github.com/go-openapi/jsonreference
22

33
require (
4-
github.com/PuerkitoBio/purell v1.1.1
5-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
64
github.com/go-openapi/jsonpointer v0.19.3
75
github.com/stretchr/testify v1.3.0
8-
golang.org/x/net v0.0.0-20210421230115-4e50805a0758 // indirect
96
)
107

118
go 1.13

go.sum

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
2-
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
3-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
4-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
51
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
62
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
73
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -22,14 +18,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
2218
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2319
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
2420
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
25-
golang.org/x/net v0.0.0-20210421230115-4e50805a0758 h1:aEpZnXcAmXkd6AvLb2OPt+EN1Zu/8Ne3pCqPjja5PXY=
26-
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
27-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
28-
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
29-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
30-
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
31-
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
32-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
3321
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3422
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
3523
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

internal/normalize_url.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package internal
2+
3+
import (
4+
"net/url"
5+
"regexp"
6+
"strings"
7+
)
8+
9+
const (
10+
defaultHttpPort = ":80"
11+
defaultHttpsPort = ":443"
12+
)
13+
14+
// Regular expressions used by the normalizations
15+
var rxPort = regexp.MustCompile(`(:\d+)/?$`)
16+
var rxDupSlashes = regexp.MustCompile(`/{2,}`)
17+
18+
// NormalizeURL will normalize the specified URL
19+
// This was added to replace a previous call to the no longer maintained purell library:
20+
// The call that was used looked like the following:
21+
// url.Parse(purell.NormalizeURL(parsed, purell.FlagsSafe|purell.FlagRemoveDuplicateSlashes))
22+
//
23+
// To explain all that was included in the call above, purell.FlagsSafe was really just the following:
24+
// - FlagLowercaseScheme
25+
// - FlagLowercaseHost
26+
// - FlagRemoveDefaultPort
27+
// - FlagRemoveDuplicateSlashes (and this was mixed in with the |)
28+
func NormalizeURL(u *url.URL) {
29+
lowercaseScheme(u)
30+
lowercaseHost(u)
31+
removeDefaultPort(u)
32+
removeDuplicateSlashes(u)
33+
}
34+
35+
func lowercaseScheme(u *url.URL) {
36+
if len(u.Scheme) > 0 {
37+
u.Scheme = strings.ToLower(u.Scheme)
38+
}
39+
}
40+
41+
func lowercaseHost(u *url.URL) {
42+
if len(u.Host) > 0 {
43+
u.Host = strings.ToLower(u.Host)
44+
}
45+
}
46+
47+
func removeDefaultPort(u *url.URL) {
48+
if len(u.Host) > 0 {
49+
scheme := strings.ToLower(u.Scheme)
50+
u.Host = rxPort.ReplaceAllStringFunc(u.Host, func(val string) string {
51+
if (scheme == "http" && val == defaultHttpPort) || (scheme == "https" && val == defaultHttpsPort) {
52+
return ""
53+
}
54+
return val
55+
})
56+
}
57+
}
58+
59+
func removeDuplicateSlashes(u *url.URL) {
60+
if len(u.Path) > 0 {
61+
u.Path = rxDupSlashes.ReplaceAllString(u.Path, "/")
62+
}
63+
}

reference.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
"net/url"
3131
"strings"
3232

33-
"github.com/PuerkitoBio/purell"
3433
"github.com/go-openapi/jsonpointer"
34+
"github.com/go-openapi/jsonreference/internal"
3535
)
3636

3737
const (
@@ -114,7 +114,9 @@ func (r *Ref) parse(jsonReferenceString string) error {
114114
return err
115115
}
116116

117-
r.referenceURL, _ = url.Parse(purell.NormalizeURL(parsed, purell.FlagsSafe|purell.FlagRemoveDuplicateSlashes))
117+
internal.NormalizeURL(parsed)
118+
119+
r.referenceURL = parsed
118120
refURL := r.referenceURL
119121

120122
if refURL.Scheme != "" && refURL.Host != "" {

0 commit comments

Comments
 (0)