Skip to content

Commit fa70d43

Browse files
committed
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.
1 parent 079d8ca commit fa70d43

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

includes/Wpup/UpdateServer.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ public static function guessServerUrl() {
3636
$path = $_SERVER['SCRIPT_NAME'];
3737

3838
if ( basename($path) === 'index.php' ) {
39-
$dir = dirname($path);
39+
$path = dirname($path);
4040
if ( DIRECTORY_SEPARATOR === '/' ) {
41-
$path = $dir . '/';
42-
} else {
43-
// Fix Windows
44-
$path = str_replace('\\', '/', $dir);
45-
//Make sure there's a trailing slash.
46-
if ( substr($path, -1) !== '/' ) {
47-
$path .= '/';
48-
}
41+
//Normalize Windows paths.
42+
$path = str_replace('\\', '/', $path);
43+
}
44+
//Make sure there's a trailing slash.
45+
if ( substr($path, -1) !== '/' ) {
46+
$path .= '/';
4947
}
5048
}
5149

0 commit comments

Comments
 (0)