diff --git a/features/server.feature b/features/server.feature index a551e0e..963720e 100644 --- a/features/server.feature +++ b/features/server.feature @@ -12,9 +12,11 @@ Feature: Serve WordPress locally Just another WordPress site """ - When I run `curl -sS localhost:8181/license.txt > /tmp/license.txt` - And I run `cmp /tmp/license.txt license.txt` - Then STDOUT should be empty + When I run `curl -sSL http://localhost:8181/license.txt` + Then STDOUT should contain: + """ + WordPress - Web publishing software + """ Scenario: Passthrough arguments to PHP binary Given a WP install @@ -43,8 +45,8 @@ Feature: Serve WordPress locally Scenario: Pretty permalinks Given a WP install And I launch in the background `wp server --host=localhost --port=8183` - And I run `wp option update permalink_structure '/%postname%/'` - And I run `wp rewrite flush` + # No leading slash for Windows compatibility on CI. + And I run `wp rewrite structure "%postname%/"` When I run `curl -sSL http://localhost:8183/hello-world/` Then STDOUT should contain: diff --git a/router.php b/router.php index 68bae24..a0c22df 100644 --- a/router.php +++ b/router.php @@ -137,21 +137,25 @@ static function ( $buffer ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url $wpcli_server_path = '/' . ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ) )['path'], '/' ); -if ( file_exists( $wpcli_server_root . $wpcli_server_path ) ) { - if ( is_dir( $wpcli_server_root . $wpcli_server_path ) && substr( $wpcli_server_path, -1 ) !== '/' ) { +$wpcli_server_file = $wpcli_server_root . $wpcli_server_path; +// Normalize slashes for file operations +$wpcli_server_file = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, $wpcli_server_file ); + +if ( file_exists( $wpcli_server_file ) ) { + if ( is_dir( $wpcli_server_file ) && substr( $wpcli_server_path, -1 ) !== '/' ) { header( "Location: $wpcli_server_path/" ); exit; } // Check if this is a PHP file by examining the extension - if ( pathinfo( $wpcli_server_path, PATHINFO_EXTENSION ) === 'php' ) { + if ( pathinfo( $wpcli_server_file, PATHINFO_EXTENSION ) === 'php' ) { // Set $_SERVER variables to mimic direct access to the PHP file $_SERVER['SCRIPT_NAME'] = $wpcli_server_path; $_SERVER['PHP_SELF'] = $wpcli_server_path; - $_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . $wpcli_server_path; + $_SERVER['SCRIPT_FILENAME'] = $wpcli_server_file; - chdir( dirname( $wpcli_server_root . $wpcli_server_path ) ); - require_once $wpcli_server_root . $wpcli_server_path; + chdir( dirname( $wpcli_server_file ) ); + require_once $wpcli_server_file; } else { return false; } @@ -159,7 +163,8 @@ static function ( $buffer ) { // File doesn't exist - route to index.php for pretty permalinks $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PHP_SELF'] = '/index.php'; - $_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . '/index.php'; + $_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . DIRECTORY_SEPARATOR . 'index.php'; + $_SERVER['PATH_INFO'] = $wpcli_server_path; // Help WordPress parse request chdir( $wpcli_server_root ); require_once 'index.php';