Skip to content

Commit

Permalink
Fix occasional double slashes in download URLs.
Browse files Browse the repository at this point in the history
In some environments, the guessServerUrl() method could return an invalid URL containing two forward slashes "//" instead of one. This caused update downloads to fail in WP 4.6. See bug report:
YahnisElsts/plugin-update-checker#66

The bug was in the *nix-like branch in guessServerUrl() that always added a forward slash to the path, even if there was one there already. Fixed by simplifying the method and only adding the slash only when necessary.
  • Loading branch information
YahnisElsts committed Aug 24, 2016
1 parent 079d8ca commit fa70d43
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions includes/Wpup/UpdateServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ public static function guessServerUrl() {
$path = $_SERVER['SCRIPT_NAME'];

if ( basename($path) === 'index.php' ) {
$dir = dirname($path);
$path = dirname($path);
if ( DIRECTORY_SEPARATOR === '/' ) {
$path = $dir . '/';
} else {
// Fix Windows
$path = str_replace('\\', '/', $dir);
//Make sure there's a trailing slash.
if ( substr($path, -1) !== '/' ) {
$path .= '/';
}
//Normalize Windows paths.
$path = str_replace('\\', '/', $path);
}
//Make sure there's a trailing slash.
if ( substr($path, -1) !== '/' ) {
$path .= '/';
}
}

Expand Down

0 comments on commit fa70d43

Please sign in to comment.