Skip to content

Fix GH-17201: Dom\TokenList issues with interned string replace #17207

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ext/dom/tests/gh17201.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-17201 (Dom\TokenList issues with interned string replace)
--EXTENSIONS--
dom
--INI--
opcache.protect_memory=1
--FILE--
<?php
$dom = DOM\XMLDocument::createFromString('<root class="AA B C"/>');
$element = $dom->documentElement;
$list = $element->classList;
$list->replace('AA', 'AB'); // Use interned string
foreach ($list as $entry) {
var_dump($entry);
}
?>
--EXPECT--
string(2) "AB"
string(1) "B"
string(1) "C"
3 changes: 2 additions & 1 deletion ext/dom/token_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ PHP_METHOD(Dom_TokenList, replace)
/* It already exists, remove token instead. */
zend_hash_del_bucket(token_set, bucket);
} else {
Z_STR(bucket->val) = new_token;
/* Need to use ZVAL_STR instead of Z_STR to reset the type flags. */
ZVAL_STR(&bucket->val, new_token);
}

/* 5. Run the update steps. */
Expand Down
Loading