Skip to content

Commit 6a8765f

Browse files
committed
Adds ftp support. Closes #18
1 parent e38c0cb commit 6a8765f

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

library/Pdp/Parser.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class Parser
2222
{
23-
const SCHEME_PATTERN = '#^https?://#i';
23+
const SCHEME_PATTERN = '#^(http|ftp)s?://#i';
2424

2525
/**
2626
* @var PublicSuffixList Public Suffix List
@@ -57,9 +57,7 @@ public function parseUrl($url)
5757
'fragment' => null,
5858
);
5959

60-
preg_match(self::SCHEME_PATTERN, $url, $schemeMatches);
61-
62-
if (empty($schemeMatches)) {
60+
if (preg_match(self::SCHEME_PATTERN, $url, $schemeMatches) === 0) {
6361
$url = 'http://' . preg_replace('#^//#', '', $url, 1);
6462
}
6563

tests/library/Pdp/ParserTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ public function parseDataProvider()
132132
// END https://github.com/jeremykendall/php-domain-parser/issues/16
133133
// Test schemeless url
134134
array('//www.broken.webhop.biz', 'webhop.biz', 'broken.webhop.biz', 'www', 'www.broken.webhop.biz'),
135+
// Test ftp support - https://github.com/jeremykendall/php-domain-parser/issues/18
136+
array('ftp://www.waxaudio.com.au/audio/albums/the_mashening', 'com.au', 'waxaudio.com.au', 'www', 'www.waxaudio.com.au'),
137+
array('ftps://test.k12.ak.us', 'k12.ak.us', 'test.k12.ak.us', null, 'test.k12.ak.us'),
135138
);
136139
}
137140
}

tests/library/Pdp/Uri/UrlTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class UrlTest extends \PHPUnit_Framework_TestCase
1313
* @var Url
1414
*/
1515
protected $url;
16+
17+
/**
18+
* @var Parser
19+
*/
20+
protected $parser;
1621

1722
/**
1823
* @var string Url spec
@@ -29,8 +34,8 @@ protected function setUp()
2934
parent::setUp();
3035
$file = realpath(dirname(__DIR__) . '/../../../data/' . PublicSuffixListManager::PDP_PSL_PHP_FILE);
3136
$psl = new PublicSuffixList($file);
32-
$parser = new Parser($psl);
33-
$this->url = $parser->parseUrl($this->spec);
37+
$this->parser = new Parser($psl);
38+
$this->url = $this->parser->parseUrl($this->spec);
3439
}
3540

3641
protected function tearDown()
@@ -110,4 +115,15 @@ public function testToArray()
110115

111116
$this->assertEquals($expected, $this->url->toArray());
112117
}
118+
119+
/**
120+
* @group issue18
121+
* @see https://github.com/jeremykendall/php-domain-parser/issues/18
122+
*/
123+
public function testFtpUrlToString()
124+
{
125+
$ftpUrl = 'ftp://ftp.somewhere.com';
126+
$url = $this->parser->parseUrl($ftpUrl);
127+
$this->assertEquals($ftpUrl, $url->__toString());
128+
}
113129
}

0 commit comments

Comments
 (0)