CSS: Improve $string_escapes documentation clarity#227
CSS: Improve $string_escapes documentation clarity#227
$string_escapes documentation clarity#227Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the CSS tokenizer’s escape decoding to follow the CSS Syntax spec’s special handling for string tokens, specifically fixing how \ + newline and \ + EOF contribute to decoded string values, and aligns the test corpus accordingly.
Changes:
- Implement special string-token escape handling (
\-newline → discard both,\-EOF → discard backslash) viadecode_escapes(..., $string_escapes=true). - Update the JSON test corpus expected
normalized/valuefields for affected cases. - Add/extend PHPUnit coverage for string/URL/ident backslash-newline and backslash-EOF behaviors, and introduce a
cssPHPUnit group.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| components/DataLiberation/CSS/class-cssprocessor.php | Renames and extends escape decoding to support string-token-specific escape rules; updates call sites. |
| components/DataLiberation/Tests/CSSProcessorTest.php | Adds targeted regression tests for backslash-newline and backslash-EOF across string/URL/ident contexts; adds @group css. |
| components/DataLiberation/Tests/css-test-cases.json | Fixes expected normalized/value outputs for string tokens containing backslash-newline and backslash-EOF. |
| components/DataLiberation/Tests/CSSUrlProcessorTest.php | Adds @group css to allow running CSS-related tests via a PHPUnit group. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ( $this->is_valid_escape( $at ) ) { | ||
| ++$at; | ||
| $decoded .= $this->decode_escape_at( $at, $bytes_consumed ); |
There was a problem hiding this comment.
In the decode_range() slow path, both the normal segments appended via substr($this->css, ...) earlier in the loop and the decode_escape_at() return value here are not passed through wp_scrub_utf8(). This makes output inconsistent with the fast path (which scrubs) and can leak invalid UTF-8 if the range contains escapes/CR/FF/NUL plus invalid bytes. Consider scrubbing the appended segments (including the decoded escape output) and adding a regression test that combines an invalid byte with a backslash escape.
There was a problem hiding this comment.
This is a good spot, but not new in this PR: #228
There was a problem hiding this comment.
nice. It would be great to explore a fix+test in another pr cc @copilot
| * - \-EOF: do nothing (consume the backslash, produce no value). | ||
| * - \-newline: consume both (line continuation, produce no value). |
There was a problem hiding this comment.
@copilot Let's express that as 0x byte sequences with annotations what do they mean. This notation confuses me.
There was a problem hiding this comment.
Updated in 96b91af — the comment now uses 0x byte sequences with annotations, e.g. 0x5C (backslash) followed by 0x0A (LF), 0x0C (FF), or 0x0D (CR).
| * @return string Decoded and normalized string. | ||
| */ | ||
| private function decode_string_or_url( int $start, int $length ): string { | ||
| private function decode_range( int $start, int $length, bool $string_escapes = false ): string { |
…x notation in comments Agent-Logs-Url: https://github.com/WordPress/php-toolkit/sessions/fe9a37e8-8456-41d8-85db-ad02267619dc Co-authored-by: adamziel <205419+adamziel@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| * - \-newline is consumed as a line continuation (ignored). | ||
| * - \-EOF is silently discarded. |
There was a problem hiding this comment.
@copilot This should be consistent with the comment in the body. Below that was changed to use HEX, so lets do that here as well.
There was a problem hiding this comment.
Done in b0d082e — updated the $string_escapes docblock to use 0x5C (backslash) followed by 0x0A (LF), 0x0C (FF), or 0x0D (CR) notation, consistent with the method body.
Agent-Logs-Url: https://github.com/WordPress/php-toolkit/sessions/601e9fa1-ea30-4c5d-accc-7da80e9f849e Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com>
| * @param int $length Length of the substring to decode. | ||
| * @param bool $string_escapes Optional, default false. When true, apply special CSS string | ||
| * token escape rules: | ||
| * - 0x5C (backslash) followed by 0x0A (LF), 0x0C (FF), or 0x0D (CR) |
There was a problem hiding this comment.
@copilot Both here and below the CRLF case in not mentioned.
- Here it would be better to remove the technical details and just say that there are some additional escaping rules the apply only to strings.
- Add the CRLF case to the technical comment in the function body.
There was a problem hiding this comment.
Done in 59fe777:
- Docblock simplified to: "When true, apply additional escape rules that apply only to string tokens (CSS §4.3.5)."
- CRLF (0x0D 0x0A) case added to the technical comment in the function body.
Agent-Logs-Url: https://github.com/WordPress/php-toolkit/sessions/35229818-8e9a-4375-b689-2b947ddac989 Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
$string_escapes documentation clarity
Two comment-only improvements to the
decode_range()$string_escapesparameter following review feedback:@paramdocblock: Replace verbose 0x byte-sequence bullet list with a concise high-level description; technical details live in the function body where they belong.