Exception thrown if search phrase not found after modifying last match
need-feedback
After searching and modifying last match, search-regex gets an empty result (as expected) but tries to call `to_array()` method on `false` in `SearchRegex\Action\Action::get_results()`
https://github.com/johngodley/search-regex/blob/75bac301f03fb27587e4c0a077970c4577447cad/includes/action/class-action.php#L97-L107
### Steps to repro:
1. Search for a unique phrase found twice only in one posts (post_content) with "Modify Matches" action.
2. Modify the matches
3. The last submitted modification succeeds but leads to the exception
### Debug info:
```
Plugin: 3.1.2
WordPress: 6.8.3 (single)
PHP: 8.3.6 256M 600s
Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
JavaScript: https://[redacted]/wp-content/plugins/search-regex/search-regex.js
REST API: https://[redacted]/wp-json/
Query: ?page=search-regex.php&searchphrase=http%3A%2F%2Fwww.wrong-domain.invalid&searchflags%5B%5D=regex&searchflags%5B%5D=case&source%5B%5D=posts&filters=%5B%7B%22type%22%3A%22posts%22%2C%22items%22%3A%5B%7B%22column%22%3A%22post_type%22%2C%22logic%22%3A%22include%22%2C%22values%22%3A%5B%22post%22%2C%22page%22%5D%7D%5D%7D%5D"
```
### Stack trace:
```log
PHP Fatal error: Uncaught Error: Call to a member function to_json() on false in /var/www/[redacted]/wp-content/plugins/search-regex/includes/action/class-action.php:101
Stack trace:
#0 /var/www/[redacted]/wp-content/plugins/search-regex/includes/api/route/route-source.php(272): SearchRegex\Action\Action->get_results()
#1 /var/www/[redacted]/wp-includes/rest-api/class-wp-rest-server.php(1292): SearchRegex\Api\Route\Source_Route->saveRow()
#2 /var/www/[redacted]/wp-includes/rest-api/class-wp-rest-server.php(1125): WP_REST_Server->respond_to_request()
#3 /var/www/[redacted]/wp-includes/rest-api/class-wp-rest-server.php(439): WP_REST_Server->dispatch()
#4 /var/www/[redacted]/wp-includes/rest-api.php(459): WP_REST_Server->serve_request()
#5 /var/www/[redacted]/wp-includes/class-wp-hook.php(324): rest_api_loaded()
#6 /var/www/[redacted]/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#7 /var/www/[redacted]/wp-includes/plugin.php(565): WP_Hook->do_action()
#8 /var/www/[redacted]/wp-includes/class-wp.php(418): do_action_ref_array()
#9 /var/www/[redacted]/wp-includes/class-wp.php(818): WP->parse_request()
#10 /var/www/[redacted]/wp-includes/functions.php(1342): WP->main()
#11 /var/www/[redacted]/wp-blog-header.php(16): wp()
#12 /var/www/[redacted]/index.php(17): require('...')
#13 {main}
throw in /var/www/[redacted]/wp-content/plugins/search-regex/includes/action/class-action.php on line 101
```
1 条评论