HTML API: Ensure final / in unquoted attribute values is not treated as self-closing#12319
HTML API: Ensure final / in unquoted attribute values is not treated as self-closing#12319sirreal wants to merge 18 commits into
Conversation
|
Hi there! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| 'Self-closing flag after attribute' => array( '<div id=test />', true ), | ||
| 'Slash inside unquoted attribute value' => array( '<div id=test/>', false ), | ||
| 'Slash only unquoted attribute value' => array( '<div attr=/>', false ), | ||
| 'Attribute "=" with value ""' => array( '<div =/>', false ), |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| * @since 6.2.0 | ||
| * @ignore | ||
| * | ||
| * @return bool Whether an attribute was found before the end of the document. |
There was a problem hiding this comment.
how about we leave it as it was, but add …before the end of the document, or before some other stop condition.?
the change is placing the emphasis on whether to continue rather than whether something was found.
There was a problem hiding this comment.
I'll roll this back, it doesn't need to land with the rest of this fix.
I changed this specifically because I was confused by what the return value means here. Specifically these lines:
wordpress-develop/src/wp-includes/html-api/class-wp-html-tag-processor.php
Lines 2215 to 2223 in aa4e8ec
I was surprised because closing tags don't have attributes. I expected a false return in that case.
The return condition really indicates whether attribute parsing has reached a stop condition:
wordpress-develop/src/wp-includes/html-api/class-wp-html-tag-processor.php
Lines 998 to 1001 in aa4e8ec
wordpress-develop/src/wp-includes/html-api/class-wp-html-tag-processor.php
Lines 1467 to 1469 in aa4e8ec
wordpress-develop/src/wp-includes/html-api/class-wp-html-tag-processor.php
Lines 1677 to 1679 in aa4e8ec
It's confusing because attributes are parsed in close tags, they're just discarded.
There was a problem hiding this comment.
yeah but I think it’s good to focus on what the parser returns in the positive sense. we use it as a continuation flag because if we found an attribute, we want to continue looking for the next one.
it indicates whether to continue parsing, but a true doesn’t imply there are more attributes, only that it found an attribute. likewise, false only means that we found no attribute when attempting to parse one.
you found and fixed the existing bug in the docs: this could be the case when we finish parsing the document or it could be the case that there was some unexpected stop condition.
in other words, if we focus on the stop condition, we have an asymmetric return value: in the true sense it says “keep going” but doesn’t speak to whether we found an attribute. in harmony with all of the other boolean-returning methods, a false signifies that it found what it was looking for or not.
dmsnell
left a comment
There was a problem hiding this comment.
Left a note and a pre-approval.
There’s a case of removing an attribute and leaving an ambiguous trailing /> that came up in my fuzz-testing, but I may have fixed it already.
<div a b=3 /b>
<!-- remove attribute b -->
<div a />something like this
Nice one, I'll see if variant of that is reproducible and add some unit tests. |
|
I plan to land this and address that on its own. Attribute removal behavior with the self-closing flag are a different issue. |
A trailing slash in an unquoted attribute value was incorrectly treated as a self-closing flag. For example, `<div id=test/>` is a tag with the `id` attribute value `test/`, not a self-closing tag. Developed in #12319. Props jonsurrell, dmsnell. See #65372. git-svn-id: https://develop.svn.wordpress.org/trunk@62595 602fd350-edb4-49c9-b593-d223f7449a82
|
Merged in r62595. |
A trailing slash in an unquoted attribute value was incorrectly treated as a self-closing flag. For example, `<div id=test/>` is a tag with the `id` attribute value `test/`, not a self-closing tag. Developed in WordPress/wordpress-develop#12319. Props jonsurrell, dmsnell. See #65372. Built from https://develop.svn.wordpress.org/trunk@62595 git-svn-id: http://core.svn.wordpress.org/trunk@61875 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Work-in-progress: #12368 |
A trailing slash in an unquoted attribute value was incorrectly treated as a self-closing flag. For example, `<div id=test/>` is a tag with the `id` attribute value `test/`, not a self-closing tag. Developed in WordPress#12319. Props jonsurrell, dmsnell. See #65372. git-svn-id: https://develop.svn.wordpress.org/trunk@62595 602fd350-edb4-49c9-b593-d223f7449a82
A trailing slash in an unquoted attribute value was incorrectly treated as a self-closing flag. For example, `<div id=test/>` is a tag with the `id` attribute value `test/`, not a self-closing tag. Developed in WordPress#12319. Props jonsurrell, dmsnell. See #65372. git-svn-id: https://develop.svn.wordpress.org/trunk@62595 602fd350-edb4-49c9-b593-d223f7449a82
<g attr=/>is not a self-closing tag. It is a tag with the[attr="/"]attribute.The self-closing flag is largely irrelevant except in foreign content and this requires a very unusual unquoted attribute value ending in
/.Trac ticket: https://core.trac.wordpress.org/ticket/65372
Use of AI Tools
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.