Conversation
dmsnell
left a comment
There was a problem hiding this comment.
Looks good, and it was on my list to verify this works based on what @ockham is doing with it. Thanks for the update.
I've tested this and it looks right and doesn't have any dramatic performance impact (though plausibly it could in some worse-case scenarios). Either way, this is a spec problem and not a convenience, so it wouldn't matter.
Thanks @adamziel
b89bed7 to
4507556
Compare
|
I forgot about With $p = new WP_HTML_Tag_Processor( '<div DATA-enabled="true">Test</div>' );
$p->next_tag();
$p->set_attribute( 'data-ENABLED', 'abc' );I went for |
|
@adamziel in keeping in line with touching as little as possible I propose it should work like so:
So for Updating the value of an attribute that already exists could arguable leave the old name which would touch the HTML less than replacing the name would, but then that takes away the ability to enforce a new naming casing on write. HTML specifies how we interpret those attributes but it doesn't mandate that attributes are written in lowercase. |
…L parsing spec. Accordingly to https://html.spec.whatwg.org/multipage/parsing.html#attribute-name-state, the uppercase letters in the attribute names should be consumed as lowercase letters, e.g. `<a HREF="#">` should be parsed as `a` with an attribute `href` (not `HREF`). In particular, the following test case should pass: ```php $p = new WP_HTML_Tag_Processor( '<div DATA-enabled="true">Test</div>' ); $p->next_tag(); $p->get_attribute( 'data-enabled' ); $this->assertEquals( 'true', $p->get_attribute( 'DATA-enabled' ) ); $this->assertEquals( 'true', $p->get_attribute( 'data-enabled' ) ); $this->assertEquals( 'true', $p->get_attribute( 'DATA-ENABLED' ) ); ```
e5f5217 to
048e84a
Compare
048e84a to
46ecc4b
Compare
|
@adamziel I pushed a commit implementing the behavior I suggested. we can remove those commits if you think it's a mistake. in addition I updated the comments to quote directly from the spec and linked to a different section which discusses the meaning of the attribute name instead of the description of how to parse them. figured that might be more normative. |
|
Thanks both of you! |
Accordingly to
https://html.spec.whatwg.org/multipage/parsing.html#attribute-name-state, the uppercase letters in the attribute names should be consumed as lowercase letters, e.g.
<a HREF="#">should be parsed asawith an attributehref(notHREF).In particular, the following test case should pass:
cc @dmsnell @ockham