wp-cli / wp-config-transformer

Programmatically edit a wp-config.php file
MIT License
80 stars 25 forks source link

Config transformer does not properly update wp-config.php file #15

Closed cldevs closed 5 years ago

cldevs commented 5 years ago

Duplicate of https://github.com/wp-cli/config-command/issues/83 but entered into appropriate repo for tracking.

Again, the issue is that a semi-colon somewhere in the string of a value fools the transformer into thinking that's the end of the key-value declaration which results in a corrupt wp-config.php file and winds up taking down a Wordpress site.

WPConfigTransformer.php - Line 199-203 $contents = preg_replace( sprintf( '/(?<=^|;|<\?php\s|<\?\s)(\s*?)%s/m', preg_quote( trim( $old_src ), '/' ) ), '$1' . str_replace( '$', '\$', trim( $new_src ) ), $this->wp_config_src );

Is this just a matter of including the ending newline character at the end of each search string (e.g. after the semi-colon) so it matches right to the end of the line instead of stopping part-way? Then including a newline character at the end of the replace? Any other implications here?

schlessera commented 5 years ago

I transferred the original issue as it has more context. I'll copy the above in there and close this one as a duplicate of #17