Skip to content

Commit

Permalink
Adds ftp support. Closes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykendall committed Dec 24, 2013
1 parent e38c0cb commit 6a8765f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 2 additions & 4 deletions library/Pdp/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class Parser
{
const SCHEME_PATTERN = '#^https?://#i';
const SCHEME_PATTERN = '#^(http|ftp)s?://#i';

/**
* @var PublicSuffixList Public Suffix List
Expand Down Expand Up @@ -57,9 +57,7 @@ public function parseUrl($url)
'fragment' => null,
);

preg_match(self::SCHEME_PATTERN, $url, $schemeMatches);

if (empty($schemeMatches)) {
if (preg_match(self::SCHEME_PATTERN, $url, $schemeMatches) === 0) {
$url = 'http://' . preg_replace('#^//#', '', $url, 1);
}

Expand Down
3 changes: 3 additions & 0 deletions tests/library/Pdp/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public function parseDataProvider()
// END https://github.com/jeremykendall/php-domain-parser/issues/16
// Test schemeless url
array('//www.broken.webhop.biz', 'webhop.biz', 'broken.webhop.biz', 'www', 'www.broken.webhop.biz'),
// Test ftp support - https://github.com/jeremykendall/php-domain-parser/issues/18
array('ftp://www.waxaudio.com.au/audio/albums/the_mashening', 'com.au', 'waxaudio.com.au', 'www', 'www.waxaudio.com.au'),
array('ftps://test.k12.ak.us', 'k12.ak.us', 'test.k12.ak.us', null, 'test.k12.ak.us'),
);
}
}
20 changes: 18 additions & 2 deletions tests/library/Pdp/Uri/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class UrlTest extends \PHPUnit_Framework_TestCase
* @var Url
*/
protected $url;

/**
* @var Parser
*/
protected $parser;

/**
* @var string Url spec
Expand All @@ -29,8 +34,8 @@ protected function setUp()
parent::setUp();
$file = realpath(dirname(__DIR__) . '/../../../data/' . PublicSuffixListManager::PDP_PSL_PHP_FILE);
$psl = new PublicSuffixList($file);
$parser = new Parser($psl);
$this->url = $parser->parseUrl($this->spec);
$this->parser = new Parser($psl);
$this->url = $this->parser->parseUrl($this->spec);
}

protected function tearDown()
Expand Down Expand Up @@ -110,4 +115,15 @@ public function testToArray()

$this->assertEquals($expected, $this->url->toArray());
}

/**
* @group issue18
* @see https://github.com/jeremykendall/php-domain-parser/issues/18
*/
public function testFtpUrlToString()
{
$ftpUrl = 'ftp://ftp.somewhere.com';
$url = $this->parser->parseUrl($ftpUrl);
$this->assertEquals($ftpUrl, $url->__toString());
}
}

0 comments on commit 6a8765f

Please sign in to comment.