-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML API: Implement reset_insertion_mode #6020
HTML API: Implement reset_insertion_mode #6020
Conversation
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. |
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. |
596a977
to
b893d3c
Compare
b893d3c
to
39d04fb
Compare
This allows it to be better tested via public properties.
39d04fb
to
17935b9
Compare
|
||
foreach ( $stack_of_open_elements as $i => $tag_name ) { | ||
if ( ! ctype_upper( $tag_name ) ) { | ||
throw new Error( 'Expected upper case tag names.' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this error message. for one, it's testing the wrong thing in the wrong test. for two, it doesn't help explain why this test is failing.
what's the purpose of this? is it to get around markers and text nodes and comments, etc…?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sirreal I really wanted to push this out but I still have some concerns. I think that the code is wrong, and I've left two test cases failing because I think that they should be asserting different results than they are, and it hinges on how the context node is handled.
I tried running some JS code to force the context node in a fragment parser but I ended up getting confused.
with all this being said it brings me back to some doubt about how we're testing the internals and not the public interface. I started moving the reset_insertion_mode()
method into the HTML Processor, as I feel like it belongs there, but then I realized that makes testing it really difficult, as you can't set it up without the rest of the HTML Processor.
how did you establish your test cases? how do we know they are correct? I'm a bit worried that some of the test cases are setting themselves up in ways that I don't think we should ever get into in real code.
As the HTML Processor starts to support other insertion modes outside of "IN BODY" it needs to be aware of those other modes. This patch introduces the missing insertion modes in preparation for adding that support. Extracted as necessary prep work to the following more complete change: WordPress#6020 Props jonsurrell. See #61549.
As the HTML Processor starts to support other insertion modes outside of "IN BODY" it needs to be aware of those other modes. This patch introduces the missing insertion modes in preparation for adding that support. Extracted as necessary prep work to the following more complete change: #6020 Props jonsurrell. See #61549. git-svn-id: https://develop.svn.wordpress.org/trunk@58631 602fd350-edb4-49c9-b593-d223f7449a82
As the HTML Processor starts to support other insertion modes outside of "IN BODY" it needs to be aware of those other modes. This patch introduces the missing insertion modes in preparation for adding that support. Extracted as necessary prep work to the following more complete change: WordPress/wordpress-develop#6020 Props jonsurrell. See #61549. Built from https://develop.svn.wordpress.org/trunk@58631 git-svn-id: http://core.svn.wordpress.org/trunk@58060 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@sirreal I've merged in |
As the HTML Processor starts to support other insertion modes outside of "IN BODY" it needs to be aware of those other modes. This patch introduces the missing insertion modes in preparation for adding that support. Extracted as necessary prep work to the following more complete change: WordPress/wordpress-develop#6020 Props jonsurrell. See #61549. Built from https://develop.svn.wordpress.org/trunk@58631 git-svn-id: https://core.svn.wordpress.org/trunk@58060 1a063a9b-81f0-0310-95a4-ce76da25c4cd
At this point I feel pretty good about the implementation and whatever direction you want to take it. @dmsnell I think you wanted to move it to the HTML Processor, that's fine with me. That's where I put it originally and only moved it so it was easily testable. I'm fine with removing the internals tests and moving the implementation 👍 |
if ( $node === $first_node ) { | ||
$last = true; | ||
if ( isset( $this->context_node ) ) { | ||
$node = new WP_HTML_Token( 'context-node', $this->context_node[0], false ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this class, we use the context_node
directly:
$node = new WP_HTML_Token( 'context-node', $this->context_node[0], false ); | |
$node = $this->context_node; |
Noting that because of the inherent challenges in testing this change, we're going to lean on the existing The challenge is that this is an internal implementation and it's difficult to ascertain what the tests should be verifying. The test cases are unclear, and testing it in isolation doesn't bear a direct impact on whether the HTML API is working properly or not. Therefore in order to avoid accidentally encoding incorrect behaviors in a unit test suite on an internal details, and to avoid architecting our code around the ability to test such internal details, we're foregoing specific new tests for this code. |
In order to add support for the SELECT and TABLE tags in the HTML Processor, it needs to implement the HTML algorithm named "reset the insertion mode appropriately". This patch implements that algorithm to unblock the additional tag support. The algorithm resets the parsing mode after specific state changes in complicated situations where alternative rules are in effect (such as rules governing how the parser handles tags found within a TABLE element). Developed in #6020 Discussed in https://core.trac.wordpress.org/ticket/61549 Props dmsnell, jonsurrell. Fixes #61549. git-svn-id: https://develop.svn.wordpress.org/trunk@58656 602fd350-edb4-49c9-b593-d223f7449a82
In order to add support for the SELECT and TABLE tags in the HTML Processor, it needs to implement the HTML algorithm named "reset the insertion mode appropriately". This patch implements that algorithm to unblock the additional tag support. The algorithm resets the parsing mode after specific state changes in complicated situations where alternative rules are in effect (such as rules governing how the parser handles tags found within a TABLE element). Developed in WordPress/wordpress-develop#6020 Discussed in https://core.trac.wordpress.org/ticket/61549 Props dmsnell, jonsurrell. Fixes #61549. Built from https://develop.svn.wordpress.org/trunk@58656 git-svn-id: http://core.svn.wordpress.org/trunk@58070 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In order to add support for the SELECT and TABLE tags in the HTML Processor, it needs to implement the HTML algorithm named "reset the insertion mode appropriately". This patch implements that algorithm to unblock the additional tag support. The algorithm resets the parsing mode after specific state changes in complicated situations where alternative rules are in effect (such as rules governing how the parser handles tags found within a TABLE element). Developed in WordPress/wordpress-develop#6020 Discussed in https://core.trac.wordpress.org/ticket/61549 Props dmsnell, jonsurrell. Fixes #61549. Built from https://develop.svn.wordpress.org/trunk@58656 git-svn-id: https://core.svn.wordpress.org/trunk@58070 1a063a9b-81f0-0310-95a4-ce76da25c4cd
As the HTML Processor starts to support other insertion modes outside of "IN BODY" it needs to be aware of those other modes. This patch introduces the missing insertion modes in preparation for adding that support. Extracted as necessary prep work to the following more complete change: WordPress#6020 Props jonsurrell. See #61549. git-svn-id: https://develop.svn.wordpress.org/trunk@58631 602fd350-edb4-49c9-b593-d223f7449a82
In order to add support for the SELECT and TABLE tags in the HTML Processor, it needs to implement the HTML algorithm named "reset the insertion mode appropriately". This patch implements that algorithm to unblock the additional tag support. The algorithm resets the parsing mode after specific state changes in complicated situations where alternative rules are in effect (such as rules governing how the parser handles tags found within a TABLE element). Developed in WordPress#6020 Discussed in https://core.trac.wordpress.org/ticket/61549 Props dmsnell, jonsurrell. Fixes #61549. git-svn-id: https://develop.svn.wordpress.org/trunk@58656 602fd350-edb4-49c9-b593-d223f7449a82
Trac Ticket: Core-61549
See HTML Spec: Add an implementation and tests for "reset the insertion mode appropriately".
This unblocks work to support more tags:
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.