-
Notifications
You must be signed in to change notification settings - Fork 46
Add JSON handling for search/replace in custom tables and nested JSON #226
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,7 +200,20 @@ private function run_recursively( $data, $serialised, $recursion_level = 0, $vis | |
| if ( $this->logging ) { | ||
| $old_data = $data; | ||
| } | ||
| if ( $this->regex ) { | ||
|
|
||
| // Try to decode as a JSON object or array and recurse into the | ||
| // decoded structure. This properly handles URLs stored inside | ||
| // JSON-encoded columns (e.g. Gravity Forms confirmations, block | ||
| // editor font data), including nested JSON where slashes are | ||
| // double-escaped. | ||
| $json_decoded = json_decode( $data, true ); | ||
| if ( null !== $json_decoded && is_array( $json_decoded ) ) { | ||
| $json_decoded = $this->run_recursively( $json_decoded, false, $recursion_level + 1, $visited_data ); | ||
| $json_result = json_encode( $json_decoded ); | ||
| if ( false !== $json_result ) { | ||
| $data = $json_result; | ||
| } | ||
| } elseif ( $this->regex ) { | ||
|
Comment on lines
+204
to
+216
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. Attempting to // Try to decode as a JSON object or array and recurse into the
// decoded structure. This properly handles URLs stored inside
// JSON-encoded columns (e.g. Gravity Forms confirmations, block
// editor font data), including nested JSON where slashes are
// double-escaped.
if ( '' !== $data && ( '{' === $data[0] || '[' === $data[0] ) ) {
$json_decoded = json_decode( $data, true );
if ( null !== $json_decoded && is_array( $json_decoded ) ) {
$json_decoded = $this->run_recursively( $json_decoded, false, $recursion_level + 1, $visited_data );
$json_result = json_encode( $json_decoded );
if ( false !== $json_result ) {
$data = $json_result;
}
}
} elseif ( $this->regex ) { |
||
| $search_regex = $this->regex_delimiter; | ||
| $search_regex .= $this->from; | ||
| $search_regex .= $this->regex_delimiter; | ||
|
|
||
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.
The regular expression
^[\\[{]appears to be malformed as it opens a character class[but does not close it with a corresponding]. This will likely result in a database error or fail to match any rows, preventing the automatic detection of JSON columns. A more reliable and readable approach for detecting strings starting with{or[is to use an alternation.