Opened 7 weeks ago
Closed 2 weeks ago
#65582 closed task (blessed) (fixed)
HTML API: Update processing instruction parsing
| Reported by: | jonsurrell | Owned by: | jonsurrell |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.1 |
| Component: | HTML API | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description (last modified by )
Processing instruction parsing has been updated in the HTML standard. <?processing instructions ?> were transformed into comments, but are now preserved.
See the processing instruction states in the standard.
See #65581 (adds updated tests).
Change History (12)
This ticket was mentioned in PR #12424 on WordPress/wordpress-develop by @jonsurrell.
6 weeks ago
#1
- Keywords has-patch has-unit-tests added
@jonsurrell commented on PR #12424:
6 weeks ago
#2
This adds PI handling to all the relevant insertion modes. PI handling is notably missing from two places:
This change currently follows the spec for _in head noscript_ but inserts the token _in template_.
It's unclear whether these are an oversight or not. I've asked and will follow-up.
This ticket was mentioned in PR #12501 on WordPress/wordpress-develop by @jonsurrell.
5 weeks ago
#5
The HTML spec updates to introduce HTML processing instructions (PI) overlooked a few insertion modes. PI were added to those modes in https://github.com/whatwg/html/pull/12653. Update the HTML API accordingly.
Trac ticket: https://core.trac.wordpress.org/ticket/65582
Follow-up to: r62687.
#8
@
2 weeks ago
- Resolution fixed
- Status closed → reopened
Looks like the detection of whitespace after the PI target name should have been a construction with strspn() instead of strpos()
- false !== strpos( " \t\f\r\n?>", $html[ $target_at + $target_length ] ) + 1 !== strspn( $html, " \t\f\r\n?>", $target_at + $target_length, 1 )
We should fix this before the release.
#9
@
2 weeks ago
There was a recent change in r62964, it's now str_contains().
I've reviewed and don't believe there's any issue with the implementation right now. Is this a code style or performance suggestion?
(Note that the change would need to be 1 === strspn(…))
#10
@
2 weeks ago
@jonsurrell it’s a correctness question. am I misunderstanding, or is the code as-written requiring that a PI node terminate in exactly a space then a tab then a form-feed then a carriage-return then a newline then a ? then a >?
I would expect this to find zero PI nodes. my conjecture, even further muddled by the WPCS change in r62964, is that we want the node to terminate when it ends in any of the whitespace characters then ?>
#11
@
2 weeks ago
is the code as-written requiring that a PI node terminate in exactly a space then a tab then a form-feed then a carriage-return then a newline then a
?then a>?
No, that's not the condition as implemented.
str_contains( " \t\f\r\n?>", $html[ $target_at + $target_length ] )
The signature is:
function str_contains(string $haystack, string $needle): bool
So it's checking for a single source byte ($needle) in the list of valid characters $haystack (" \t\f\r\n?>").
The function is often used the other way around, where the $needle is a string literal and the $haystack is arbitrary text.
This could be changed to use strspn(), which may better align with expectations and other patterns in this file, but I don't think it's incorrect as is and there's a good amount of test coverage. If it were trying to match " \t\f\r\n?>" in the HTML input, I'd expect a lot of test failures.
we want the node to terminate when it ends in any of the whitespace characters then
?>
For a valid PI, the target must be follow by ANY of whitespace OR ? OR >.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
See #12423 (merged here) for the test addition..
Trac ticket: https://core.trac.wordpress.org/ticket/65582
## Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Model(s): Fable 5
Used for: Initial implementation.