diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 13b3956..cba872c 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -1,6 +1,6 @@ name: Go Test -on: [push] +on: [push, pull_request] jobs: diff --git a/internal/normalize_url.go b/internal/normalize_url.go index fb376fc..f0610cf 100644 --- a/internal/normalize_url.go +++ b/internal/normalize_url.go @@ -26,11 +26,16 @@ var rxDupSlashes = regexp.MustCompile(`/{2,}`) // - FlagLowercaseHost // - FlagRemoveDefaultPort // - FlagRemoveDuplicateSlashes (and this was mixed in with the |) +// +// This also normalizes the URL into its urlencoded form by removing RawPath and RawFragment. func NormalizeURL(u *url.URL) { lowercaseScheme(u) lowercaseHost(u) removeDefaultPort(u) removeDuplicateSlashes(u) + + u.RawPath = "" + u.RawFragment = "" } func lowercaseScheme(u *url.URL) { diff --git a/reference_test.go b/reference_test.go index f2476be..4145891 100644 --- a/reference_test.go +++ b/reference_test.go @@ -26,6 +26,7 @@ package jsonreference import ( + "reflect" "testing" "github.com/go-openapi/jsonpointer" @@ -421,3 +422,17 @@ func TestReferenceResolution(t *testing.T) { } } } + +func TestIdenticalURLEncoded(t *testing.T) { + expected, err := New("https://localhost/🌭#/🍔") + if err != nil { + t.Fatalf("Failed to create jsonreference: %v", err) + } + actual, err := New("https://localhost/%F0%9F%8C%AD#/%F0%9F%8D%94") + if err != nil { + t.Fatalf("Failed to create jsonreference: %v", err) + } + if !reflect.DeepEqual(expected, actual) { + t.Fatalf("expected %v (URL: %#v), got %v (URL: %#v)", expected.String(), expected.referenceURL, actual.String(), actual.referenceURL) + } +}