Skip to content

Encoding: stop ASCII scanning at the requested character limit - #319

Merged
adamziel merged 3 commits into
trunkfrom
codex/bound-utf8-ascii-scan
Sep 10, 2026
Merged

Encoding: stop ASCII scanning at the requested character limit#319
adamziel merged 3 commits into
trunkfrom
codex/bound-utf8-ascii-scan

Conversation

@adamziel

@adamziel adamziel commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Stops a one-character UTF-8 read from scanning the rest of the ASCII input. This removes the repeated scans that make full-site CSS downloads time out in WordPress/reprint#764.

For .card{color:red;margin:10px}, the CSS parser asks _wp_scan_utf8() whether a token-boundary byte can start a name. It requests one character. The helper's strspn() nevertheless scans the entire remaining ASCII suffix before returning a count of one. Doing this at each boundary makes larger stylesheets much slower.

Each ASCII byte is one character. Limit strspn() to the smaller of the remaining byte budget and character budget. Returned counts, byte offsets, and invalid-byte handling stay the same.

Tests

The new process test reads a 2.8 MB stylesheet in 1 MiB chunks, rewrites its final URL, and checks the output hash and unchanged source. The worker counts the bytes returned by the real native ASCII scan. It fails if those scans read more than eight times the input size. The released code crosses that limit after only 99 source bytes; the corrected scanner completes the file and its exact output check. This tests repeated work without depending on runner speed. Twelve scanner cases cover byte and character limits, nonzero offsets, multibyte text, and invalid bytes before or after the limit.

The same nine Reprint WordPress E2E tests took 150.9 seconds with v0.10.0 and 11.0 seconds with this one-line change applied to an isolated container's dependency copy. They check actual migrated page, stylesheet, image, and font requests, plus interrupted downloads and resume failures. No test time limit was raised.

All 29 CI checks pass, including PHP 7.2–8.5 on Linux, macOS, and Windows, lint, and documentation snippets. The nine child-process CSS tests also pass locally. The full local suite ran 6,049 tests and had one Blueprint failure about missing PHP error text; the same case fails with the unchanged UTF-8 code. The full local lint command reports existing warnings in unrelated files.

@adamziel
adamziel merged commit 2616ce3 into trunk Sep 10, 2026
29 checks passed
@adamziel
adamziel deleted the codex/bound-utf8-ascii-scan branch September 10, 2026 10: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