wp-cli / wp-config-transformer

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

preg_match_all fails with concatenated string #50

Open KBurkholder opened 10 months ago

KBurkholder commented 10 months ago

Bug Report

A string in wp-config.php like this:

define( 'WP_HOME', 'https://'.$_SERVER['HTTP_HOST'] );

Is not properly match in parse_wp_config() and ends up swallowing additional line(s).

The quick fix (for me) was to change to:

define( 'WP_HOME', "https://{$_SERVER['HTTP_HOST']}" );

But that doesn't change things in the wild.

You can see this by pasting the line in the regex101 before the /* That's all, stop editing! Happy blogging. */ line.

danielbachhuber commented 10 months ago

Thanks for the report, @KBurkholder !

Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.

tfirdaus commented 6 months ago

@danielbachhuber I've been playing around with updating the RegEx rules over here at https://regex101.com/r/ArEndA/1. It seems like I've managed to get it working in this scenario, but I've been unsuccessful trying to implement it in the source code. I'm unfamiliar with how the tests work here, especially since it seems like they're dynamically generating the file fixtures. 🤔

Out of curiousity, have we considered to parse it into AST with something like nikic/PHP-Parser? It may be more reliable than using RegEx to cover more scenarios.