-
Notifications
You must be signed in to change notification settings - Fork 384
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
Conditionally remove html[xmlns], convert html[xml:lang] to html[lang] #4194
Conversation
…lang] As Weston mentioned, neither of these is valid HTML5
src/Dom/Document.php
Outdated
return; | ||
} | ||
|
||
$xmlns = $html->attributes->getNamedItem( 'xmlns' ); |
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.
It'd probably be better to do something like $xmlns = $html->getAttribute( 'xmlns' )
.
But for some reason, $html->getAttribute( 'xmlns' )
returned ""
, even when $html->attributes->getNamedItem( 'xmlns' )
returned a DOMAttr
.
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.
Yeah, I'm not sure. I can see that $html->attributes->getNamedItem( 'xmlns' )
works across all PHP versions. I don't have a better option.
Before, if the xml:lang was non-empty and the lang was "", this would not overwrite it.
$html->removeAttributeNode( $xmlns ); | ||
} | ||
|
||
$xml_lang = $html->attributes->getNamedItem( 'xml:lang' ); |
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.
Have you considered hasAttributeNS
or getAttributeNS
?
It seems these don't work either. I would have thought at least that this would work:
$dom->documentElement->getAttributeNodeNS( 'http://www.w3.org/XML/1998/namespace', 'lang' );
But it doesn't. Perhaps it's due to loadHTML
and that the document is not XML in the first place.
Using $dom->documentElement->attributes->getNamedItem( 'xml:lang' )
works in all PHP versions 5+. So seems like a good one to use.
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.
Nice, thanks for looking at this.
src/Dom/Document.php
Outdated
return; | ||
} | ||
|
||
$xmlns = $html->attributes->getNamedItem( 'xmlns' ); |
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.
Yeah, I'm not sure. I can see that $html->attributes->getNamedItem( 'xmlns' )
works across all PHP versions. I don't have a better option.
Co-Authored-By: Weston Ruter <westonruter@google.com>
I'l make the remaining changes soon, maybe in 30 minutes to an hour. |
As Weston mentioned, this is only used in one place an shouldn't be needed.
The outstanding feedback should be addressed now, unless I misunderstood something. |
Changes look good. Note that it is difficult to test this because without #4190 the validation errors do not show up in the Validated URL screen. |
Ah, good point. Thanks for reviewing this. |
Summary
html[xmlns]
, this strips the attributehtml[xml:lang]
but nothtml[lang]
, it moves thehtml[xml:lang]
value tohtml[lang]
html[xml:lang]
attribute if it exists, no matter its valueFor example, with this change to Twenty Twenty:
...the
html[xmlns]
is stripped, and thehtml[xml:lang]
is moved tohtml[lang]
:Fixes #4132
Checklist