-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement DOMElement::className #11691
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--TEST-- | ||
DOMElement::className | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
class MyStringable { | ||
public function __toString(): string { | ||
throw new Exception("foo"); | ||
} | ||
} | ||
|
||
$dom = new DOMDocument(); | ||
$dom->loadXML('<html/>'); | ||
|
||
var_dump($dom->documentElement->className); | ||
$dom->documentElement->className = "hello & world<>"; | ||
var_dump($dom->documentElement->className); | ||
$dom->documentElement->className = ""; | ||
var_dump($dom->documentElement->className); | ||
$dom->documentElement->className = "é"; | ||
var_dump($dom->documentElement->className); | ||
$dom->documentElement->className = "\0"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might need a note in UPGRADING and the docs that this is not binary safe (i.e. maybe add an example of a string like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, shouldn't such invalid names possibly throw a DOM Exception like it is done in #11696 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, these characters are allowed in the value of the attribute, just not in the name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but libxml2 is not binary safe... sigh There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When/if they'll support fully HTML5-compliant parsing out of the box this problem should go away. |
||
var_dump($dom->documentElement->className); | ||
$dom->documentElement->className = 12345; | ||
var_dump($dom->documentElement->className); | ||
try { | ||
$dom->documentElement->className = new MyStringable(); | ||
} catch (Throwable $e) { | ||
echo "Error: ", $e->getMessage(), "\n"; | ||
} | ||
var_dump($dom->documentElement->className); | ||
echo $dom->saveXML(); | ||
|
||
?> | ||
--EXPECT-- | ||
string(0) "" | ||
string(15) "hello & world<>" | ||
string(0) "" | ||
string(2) "é" | ||
string(0) "" | ||
string(5) "12345" | ||
Error: foo | ||
string(5) "12345" | ||
<?xml version="1.0"?> | ||
<html class="12345"/> |
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 put this in the "new functions" section, because I didn't know where to put it: there is no "new properties/fields" section...