Skip to content

[PHP] Limit structured URL rewriting to mapped base components - #307

Open
adamziel wants to merge 3 commits into
trunkfrom
codex/replace-structured-url-bases
Open

[PHP] Limit structured URL rewriting to mapped base components#307
adamziel wants to merge 3 commits into
trunkfrom
codex/replace-structured-url-bases

Conversation

@adamziel

@adamziel adamziel commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

BlockMarkupUrlProcessor now changes only the mapped base in each decoded structured URL before passing the result to the existing setter.

For this mapping:

http://old.example/media => https://new.example/assets

this decoded URL:

http://old.example/media/a/./b/../%7e//boat?raw=%2f+%20#Frag%2f

becomes:

https://new.example/assets/a/./b/../%7e//boat?raw=%2f+%20#Frag%2f

The unmatched path, query, fragment, and percent-escape spelling come from the input value. The enclosing serializer still owns HTML entities, CSS quoting, and block JSON escaping. Text-node URL handling is unchanged.

WPURL::replace_base_url() owns the slash-delimited source locator and returns one validated, source-preserving decoded URL. Spellings whose base boundary cannot be located safely are left alone. BlockMarkupUrlProcessor::replace_base_url() only selects the text or structured result and calls set_url(). The setter handles source no-ops, and repeated writes to one CSS token are last-write-wins. This removes the replacement loop, CSS materialization and reseeking, and CSS URL index state from BlockMarkupUrlProcessor.

The rewrite cache stores the selected mapping rather than a rendered URL, so every structured occurrence is converted from its own decoded spelling.

Testing

The focused suites pass:

WPURLTest: 26 tests, 63 assertions
BlockMarkupUrlProcessorTest: 60 tests, 158 assertions
CSSProcessorTest: 264 tests, 365 assertions
CSSURLProcessorTest: 94 tests, 205 assertions
RewriteUrlsTest: 18 tests, 18 assertions

The complete Data Liberation suite ran 2,392 tests. Its only local failures were two remote-fixture DNS errors and the dependent frontloading assertion while network access was disabled. Changed files pass PHP 7.2 compatibility checks and git diff --check; PHPCS reports only the same two pre-existing CSS alignment warnings.

@adamziel
adamziel force-pushed the codex/replace-structured-url-bases branch from 50a4542 to bfda182 Compare August 13, 2026 15:50
@adamziel
adamziel force-pushed the codex/replace-structured-url-bases branch from bfda182 to 96934ae Compare August 13, 2026 21:28
@adamziel adamziel changed the title [PHP] Preserve unmatched URL suffixes during base replacement [PHP] Limit structured URL updates to mapped base ranges Aug 13, 2026
@adamziel
adamziel changed the base branch from trunk to codex/pin-blueprint-sqlite-test-fixture August 13, 2026 21:29
@adamziel
adamziel force-pushed the codex/replace-structured-url-bases branch from 96934ae to c1fc2b1 Compare August 13, 2026 23:53
@adamziel adamziel changed the title [PHP] Limit structured URL updates to mapped base ranges [PHP] Limit structured URL rewriting to mapped base components Aug 13, 2026
Base automatically changed from codex/pin-blueprint-sqlite-test-fixture to trunk August 14, 2026 12:50
@adamziel
adamziel force-pushed the codex/replace-structured-url-bases branch from c1fc2b1 to 6b02ecd Compare August 14, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant