Permalink
Browse files

Fix occasional double slashes in download URLs.

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...
1 parent 079d8ca commit fa70d438945120d030bcfd368ba70e9ad75704bb @YahnisElsts committed Aug 24, 2016
Showing with 7 additions and 9 deletions.
  1. +7 −9 includes/Wpup/UpdateServer.php
@@ -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 .= '/';
}
}

0 comments on commit fa70d43

Please sign in to comment.