interconnectit/Search-Replace-DB

Array to string conversion when using regex

devkinetic opened this issue · 0 comments

When I check off regex with the tool, I get the ajax error described in the readme. I looked at the XHR response and saw an error where $this->search is used as a string when its an array. When regex is not checked off, $this->search is a string. I was able to fix searching crudely by modifying line 234 of index.php from:

-$this->search = '/' . $this->search . '/' . $mods;
+$this->search = '/' . $this->search[0] . '/' . $mods;

I also ran into the same but different error when replacing and had to use $replace[0] on srdb.class.php:

public function str_replace( $search, $replace, $string, &$count = 0 ) {
        if ( $this->regex ) {
            return preg_replace( $search, $replace[0], $string, - 1, $count );
        } elseif ( function_exists( 'mb_split' ) ) {
            return self::mb_str_replace( $search, $replace[0], $string, $count );
        } else {
            return str_replace( $search, $replace[0], $string, $count );
        }
    }

I highly doubt this is the actual fix, but it shows that the POST is different for a regex, and is broken on the latest version.