From 8704f845d8a16028bc2d86dbf8477bec012da360 Mon Sep 17 00:00:00 2001 From: Jason Stallings Date: Mon, 16 Mar 2020 17:12:15 -0500 Subject: [PATCH] fix: Escape path before wp-config.php string replacement. --- php/utils.php | 7 +++++-- tests/test-utils.php | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/php/utils.php b/php/utils.php index 8e6fe19129..12c1d00e06 100644 --- a/php/utils.php +++ b/php/utils.php @@ -613,9 +613,12 @@ function is_windows() { * @return string Adapted PHP code. */ function replace_path_consts( $source, $path ) { + // Solve issue with Windows allowing single quotes in account names. + $file = addslashes( $path ); + $replacements = array( - '__FILE__' => "'$path'", - '__DIR__' => "'" . dirname( $path ) . "'", + '__FILE__' => "'$file'", + '__DIR__' => "'" . dirname( $file ) . "'", ); $old = array_keys( $replacements ); diff --git a/tests/test-utils.php b/tests/test-utils.php index 680a33956e..9073372165 100644 --- a/tests/test-utils.php +++ b/tests/test-utils.php @@ -803,4 +803,11 @@ public function dataParseUrl() { [ 'http://example.com', PHP_URL_HOST, true, 'example.com' ], ]; } + + public function testReplacePathConstsAddSlashes() { + $expected = "define( 'ABSPATH', dirname( 'C:\\\\Users\\\\test\'s\\\\site' ) . '/' );"; + $source = "define( 'ABSPATH', dirname( __FILE__ ) . '/' );"; + $actual = Utils\replace_path_consts( $source, "C:\Users\\test's\site" ); + $this->assertSame( $expected, $actual ); + } }