Discard parent segments that climb past the root - #952
Open
Amoifr wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WUCMYykYqJHv67fmwiWZip
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 #950.
combineRelativePathWithBasePath()threw when a..segment could not be popped. RFC 3986 section 5.2.4 discards those instead, so it now does.The guard had a second problem beyond the one in the issue:
count($collapsedSegments) <= 1also refused to pop a real first segment, so../bar.jsonagainst a relative basefoo/baz.jsonthrew rather than resolving tobar.json. The condition now protects only what it meant to, the leading empty segment that stands for the root of an absolute path.One thing that needs your call.
UriRetrieverTest::testResolveExcessLevelUpasserted the exception this change removes:Your acceptance list mentions
UriResolverTest, so I suspect this one was not on the radar. I turned it into an assertion on the resolved value (http://example.org/schema.json) rather than deleting it, but it is a deliberate behaviour change and it is yours to confirm.Note this does not on its own make the exact example from the issue work:
resolve('../bar.json', 'internal://mySchema')still stops earlier, on the empty base path, until #947 lands. The two are independent, as you noted, and the..handling is what this PR covers.Testing
Four new cases, all failing without the change.
Full suite green (3185 tests), same warning and skips as
main, and PHPStan reports no errors.On the measurement you asked for, with
shouldNotYieldTest()disabled: 7037 tests, 30 errors, 550 failures, identical before and after. So this neither fixes nor breaks anything in the official suite. One caveat on that run: the vendored suite here has av1directory that is not in$skippedDrafts, which makes the data provider throwv1 is not a valid constraint name(that is the single warning already present onmain). I excluded it for the measurement only, nothing of that is in this PR.