Fix StringIndexOutOfBoundsException when resolving a self $ref '#' - #149
Merged
Merged
Conversation
A $ref pointing at the schema itself ('#', or 'id#' after contextual
resolution) produces an empty fragment in JsonRef.resolveUri, which then
fails on path.charAt(0). Treat an empty fragment the same as no fragment
so the ref resolves to the schema identified by the prefix.
Fixes eclipse-vertx#141
Contributor
|
Hi @jnbdz thank you for the fix! I really appreciate it. Do you want this also in 5.1? Then I can downport it. |
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 #141
Motivation
A schema containing a self-reference
$ref: '#'(e.g. a recursive tree structure) throwsStringIndexOutOfBoundsExceptionduring resolution:In
JsonRef.resolve, a$refof#becomesid + "#"(just#when there is no$id).resolveUrithen splits it into["", ""], sohashPresentwastruewhilepathwas empty, andpath.charAt(0)threw.Changes
Treat an empty fragment (
#orid#) the same as no fragment at all, so the reference resolves to the schema identified by the prefix — the root schema for a bare#. This is "Option 1" from the issue: it removes the invalid empty-path state entirely instead of guarding thecharAtcall, and an empty fragment never carries pointer segments toreduce()anyway.Added tests covering the reproducer from the issue: direct
JsonRef.resolve, throughSchemaRepository.resolve(the path in the reported stack trace), and with a$idpresent.Note: the follow-up comment in #141 about
$ref: '#/'failing later inSchemaValidatorImplis a separate lookup-normalization issue and is not addressed here; with#fixed that workaround is no longer needed.