Encoding: stop ASCII scanning at the requested character limit - #319
Merged
Conversation
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.
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'sstrspn()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.