forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix phpGH-17802: \Dom\HTMLDocument querySelector attribute name is ca…
…se sensitive in HTML According to https://html.spec.whatwg.org/#case-sensitivity-of-selectors, the CSS selector attribute name must be converted to lowercase in HTML elements, and then compared case-sensitive to the attribute name in the element. We implement this not by doing the explicit conversion, but by a manual loop using a function that first converts the rhs characters to lowercase and keeps the lhs characters the same, achieving the same effect.
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--TEST-- | ||
GH-17802 (\Dom\HTMLDocument querySelector attribute name is case sensitive in HTML) | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
$text = <<<TEXT | ||
<html> | ||
<head> | ||
<meta charset="Windows-1252"> | ||
</head> | ||
<body> | ||
</body> | ||
</html> | ||
TEXT; | ||
|
||
$dom = \Dom\HTMLDocument::createFromString($text, options: LIBXML_NOERROR); | ||
$meta2 = $dom->head->appendChild($dom->createElementNS('urn:x', 'meta')); | ||
$meta2->setAttribute('charset', 'x'); | ||
echo $dom->saveHtml(), "\n"; | ||
|
||
echo "--- charseT ---\n"; | ||
|
||
foreach ($dom->querySelectorAll('meta[charseT]') as $entry) { | ||
var_dump($dom->saveHtml($entry)); | ||
} | ||
|
||
echo "--- charset ---\n"; | ||
|
||
foreach ($dom->querySelectorAll('meta[charset]') as $entry) { | ||
var_dump($dom->saveHtml($entry)); | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
<html><head> | ||
<meta charset="Windows-1252"> | ||
<meta charset="x"></meta></head> | ||
<body> | ||
|
||
</body></html> | ||
--- charseT --- | ||
string(29) "<meta charset="Windows-1252">" | ||
--- charset --- | ||
string(29) "<meta charset="Windows-1252">" | ||
string(25) "<meta charset="x"></meta>" |