Fix/align url normalization - #308
Merged
Merged
Conversation
jsonreference v1.0.1 stops NormalizeURL from turning a parseable URI into an unparseable one: "https://:a:443" used to come back as "https://:a", where ":a" is not a valid port. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
The normalizer kept the spelling it was handed, while jsonreference lower-cases
the host, drops a default port and re-escapes path and fragment. Both meet every
$ref - the normalizer builds the URI, and jsonreference re-renders it as soon as
the string becomes a Ref - so one document could be cached under two spellings
of itself, and a $ref written back by denormalizeRef did not normalize to what
it came from.
normalizeURI and normalizeBase now end in canonicalString, which renders through
NewRef. Only the branch returning a $ref that is already canonical and the two
returns of normalizeBase were spelling their own answer; a relative $ref went
through the join onto the base, which already re-rendered. A URI jsonreference
cannot parse is returned as it stands and logged, rather than panicking through
MustCreateRef.
forgetSpelling drops url.URL.RawPath and RawFragment once Path has been rewritten
by path.Clean or by the join. String returns RawPath whenever it still decodes to
Path, so a stale one could be rendered instead: normalizeBase("%2F") returned
"file://%2F", where the escaped form has no leading slash and what is left reads
as an authority - a base that no longer parses.
FuzzNormalizer drops the respelled() fence its fourth property carried, so
denormalizing now has to round-trip for every input rather than for those the two
sides happened to spell alike. 9.6M executions clean. TestNormalizer_Canonicalization
and TestNormalizer_CanonicalBase pin the rules case by case, including the
degenerate authorities, the runs of slashes and the escaping.
One rule is recorded rather than fixed, in TestNormalizer_EscapedSlashIsDecoded:
jsonreference decodes %2F into a separator, which RFC 3986 section 6.2.2.2 forbids. A
$ref loses the escape anyway when the document model turns it into a Ref, so
keeping it in the normalizer would only hide that. It belongs upstream.
Also drops the parentheses in expander.go that gofumpt flags, untouched since
2021, so a full golangci-lint run comes out clean.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
❌ 2 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist