Repository navigation
Percent-encode "#" in URI fragments - #153
Open
MohitSAGAR11 wants to merge 1 commit into
Open
MohitSAGAR11 wants to merge 1 commit into
MohitSAGAR11 wants to merge 1 commit into
Conversation
encodeURI leaves "#" as is, so a "#" in a property name produced locations like "#/a#b", and a $ref to "#/$defs/a%23b" couldn't be resolved because decodeURI doesn't decode "%23". Fragments are now built with one helper that also encodes "#", and anchorLocation decodes with decodeURIComponent like Instance.get and uriFragment already do. Fixes hyperjump-io#147
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.
Fixes #147
encodeURIleaves#as is, so a#in a property name produced locations like#/a#b. Going the other way,anchorLocationuseddecodeURI, which doesn't decode%23, so$ref: "#/$defs/a%23b"couldn't be resolved.Changes
encodeUriFragmentinlib/common.jsis the helper you suggested:encodeURI(fragment).replaceAll("#", "%23"). It's used everywhere a fragment is built:computeUriinlib/instance.js(instance locations)canonicalUriinlib/schema.js(keyword locations)$dynamicAnchorand legacy$dynamicAnchorURIsanchorLocationdecodes withdecodeURIComponent, the same asInstance.getanduriFragmentalready do.Tests
Added to
lib/output-basic.spec.ts. All three fail without the fix:a '#' in a property name is percent-encoded:instanceLocationis#/a%23bandabsoluteKeywordLocationends in/properties/a%23b/type.a $ref to a percent-encoded '#':$ref: "#/$defs/a%23b"resolves.a $dynamicAnchor under a '#' in a property name:$dynamicRefresolves to an anchor under$defs/a#b.npm test, type-check and lint pass.One note, unrelated to this PR: with the current JSON-Schema-Test-Suite
main,mainhere fails one v1 case,"--" in the 3rd and 4th position is valid(ab--cd.example). It was added in json-schema-org/JSON-Schema-Test-Suite#1264 with compatibility4,<=6,9999, but the v1hostnamehandler usesisAsciiIdn. CI seems to still be getting the suite from before that PR, which is why it's green.