Skip to content
Merged
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
32 changes: 32 additions & 0 deletions features/search-replace.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,38 @@ Feature: Do global search/replace
a:1:{i:0;O:10:"CornFlakes":0:{}}
"""

Scenario: Search-replace updates iterable dictionary objects without dynamic property deprecations

Given a WP install
And a search-replace-case-insensitive-dictionary.php file:
"""
<?php
WP_CLI::add_hook( 'search_replace_unserialize_options', function() {
return [ 'allowed_classes' => [ 'stdClass', 'WpOrg\Requests\Utility\CaseInsensitiveDictionary' ] ];
} );
$replacer = new \WP_CLI\SearchReplacer( 'old.example.com', 'new.example.com', true );
echo $replacer->run(
serialize(
new \WpOrg\Requests\Utility\CaseInsensitiveDictionary(
[
'date' => 'https://old.example.com/feed',
]
)
)
);
"""

When I run `wp eval-file search-replace-case-insensitive-dictionary.php`
Then STDERR should be empty
And STDOUT should contain:
"""
https://new.example.com/feed
"""
And STDOUT should not contain:
"""
https://old.example.com/feed
"""

@require-mysql
Scenario: The search_replace_unserialize_options hook allows overriding allowed_classes for unserialize

Expand Down
8 changes: 7 additions & 1 deletion src/WP_CLI/SearchReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,14 @@ private function run_recursively( $data, $serialised, $recursion_level = 0, $vis
);
} else {
try {
$is_array_access = $data instanceof \ArrayAccess;
foreach ( $data as $key => $value ) {
$data->$key = $this->run_recursively( $value, false, $recursion_level + 1, $visited_data );
$value = $this->run_recursively( $value, false, $recursion_level + 1, $visited_data );
if ( $is_array_access ) {
$data[ $key ] = $value;
} else {
$data->$key = $value;
}
Comment thread
swissspidy marked this conversation as resolved.
}
} catch ( \Error $exception ) { // phpcs:ignore PHPCompatibility.Classes.NewClasses.errorFound
// This error is thrown when the object that was unserialized cannot be iterated upon.
Expand Down
Loading