Skip to content

Commit 1c71861

Browse files
committed
Fix: Prevents invalid wp-config.php when passwords contain double quotes
1 parent c3c86ec commit 1c71861

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

features/config-create.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,22 @@ Feature: Create a wp-config file
243243
PasswordWith'SingleQuotes'
244244
"""
245245
246+
Scenario: Passwords with special characters and double quotes
247+
Given an empty directory
248+
And WP files
249+
250+
When I run `wp config create --skip-check --dbname=somedb --dbuser=someuser --dbpass='p@(ss){w0r?d><}"!With"DoubleQuotes'`
251+
Then the wp-config.php file should contain:
252+
"""
253+
define( 'DB_PASSWORD', 'p@(ss){w0r?d><}"!With"DoubleQuotes' )
254+
"""
255+
256+
When I run `wp config get DB_PASSWORD`
257+
Then STDOUT should be:
258+
"""
259+
p@(ss){w0r?d><}"!With"DoubleQuotes
260+
"""
261+
246262
@require-mysql @require-mysql-5.7
247263
Scenario: Configure with required SSL connection
248264
Given an empty directory

src/Config_Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,8 @@ private function escape_config_value( $key, $value ) {
12401240
}
12411241

12421242
if ( is_string( $value ) ) {
1243-
return addslashes( $value );
1243+
// For single-quoted strings, only escape single quotes; double quotes don't need escaping
1244+
return str_replace( "'", "\\'", $value );
12441245
}
12451246

12461247
return $value;

0 commit comments

Comments
 (0)