Skip to content

Commit

Permalink
fix github CDN URL should not be rewritten if version is already incl…
Browse files Browse the repository at this point in the history
…uded

jakoch#35
  • Loading branch information
berlinger-rarents committed Sep 29, 2016
1 parent 851aadc commit daaf790
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/PhantomInstaller/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 10 additions & 2 deletions tests/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit daaf790

Please sign in to comment.