You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR extends the URL validator with an allowFragments flag (default true) that rejects URL fragments — including the empty-fragment case (#) — when disabled. Backward compatibility is preserved by defaulting to true.
src/Validator/URL.php: adds the allowFragments constructor parameter, updates getDescription() to append "and without a fragment component" when needed, and adds a parse_url(PHP_URL_FRAGMENT) !== null guard in isValid().
tests/Validator/URLTest.php: adds testDisallowFragments and testDisallowFragmentsAllowedSchemes covering valid URLs, non-empty fragments, empty fragments, and scheme restrictions; also adds a fragment URL to the default-allow test.
Confidence Score: 5/5
Safe to merge — the change is additive, backward-compatible, and the fragment-detection logic is correct for both populated and empty fragments.
The new flag defaults to true, leaving all existing callers unaffected. The parse_url(PHP_URL_FRAGMENT) !== null guard correctly handles populated fragments (string), empty fragments (empty string ''), and missing fragments (null), all of which are exercised by the new tests.
No files require special attention.
Important Files Changed
Filename
Overview
src/Validator/URL.php
Adds allowFragments constructor param (default true for backwards compat) with correct parse_url(PHP_URL_FRAGMENT) !== null guard that rejects both populated and empty (#) fragments.
tests/Validator/URLTest.php
Adds two new test methods covering fragment-disallowed mode standalone and with scheme restrictions, including the empty-fragment edge case.
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
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.
What does this PR do?
allowFragmentsflag toUtopia\Validator\URL, defaulting totruefor backwards compatibility.https://example.com/callback#.Test Plan
composer testcomposer test -- --filter URLTestcomposer lint