diff --git a/src/PhantomInstaller/Installer.php b/src/PhantomInstaller/Installer.php index 90f0bb4..a015c05 100644 --- a/src/PhantomInstaller/Installer.php +++ b/src/PhantomInstaller/Installer.php @@ -528,18 +528,16 @@ public function getCdnUrl($version) $url = static::PHANTOMJS_CDNURL_DEFAULT; } - $url = strtolower($url); - - // add version to URL when using "github.com/medium/phantomjs" - if (strpos($url, 'github.com/medium/phantomjs') !== false) { - return 'https://github.com/medium/phantomjs/releases/download/v' . $version . '/'; - } - // add slash at the end of the URL, if missing if ($url[strlen($url) - 1] != '/') { $url .= '/'; } + // add version to URL when using "github.com/medium/phantomjs" + if (substr(strtolower($url), -28) == 'github.com/medium/phantomjs/') { + $url .= 'releases/download/v' . $version . '/'; + } + return $url; } diff --git a/tests/InstallerTest.php b/tests/InstallerTest.php index aade110..3114548 100644 --- a/tests/InstallerTest.php +++ b/tests/InstallerTest.php @@ -110,10 +110,18 @@ public function testSpecialGithubPatternForCdnUrl() { $this->setUpForGetCdnUrl(); $version = '1.0.0'; - $configuredCdnUrl = 'https://github.com/medium/phantomjs'; + + // Test rewrite for the Medium url as documented + $configuredCdnUrl = 'https://github.com/Medium/phantomjs'; + $_ENV['PHANTOMJS_CDNURL'] = $configuredCdnUrl; + $cdnurl = $this->object->getCdnUrl($version); + $this->assertSame($configuredCdnUrl . '/releases/download/v' . $version . '/', $cdnurl); + + // Test that a longer url is not rewritten + $configuredCdnUrl = 'https://github.com/Medium/phantomjs/releases/download/v1.9.19/'; $_ENV['PHANTOMJS_CDNURL'] = $configuredCdnUrl; $cdnurl = $this->object->getCdnUrl($version); - $this->assertSame('https://github.com/medium/phantomjs/releases/download/v' . $version . '/', $cdnurl); + $this->assertSame($configuredCdnUrl, $cdnurl); } /**