Skip to content

Commit

Permalink
Improve port parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkott committed Feb 22, 2017
1 parent ff0a1bf commit 117be15
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Weew/Url/UrlParser.php
Expand Up @@ -64,7 +64,7 @@ protected function parseSegments($string) {
'(:(?P<password>.*?)' .
')@)?' .
'(?P<host>[^:\/\s]+)?' .
'(:(?P<port>[^\/]*))?' .
'(:(?P<port>\d*))?' .
'(?P<path>[^#\?]*)?' .
'(\?(?P<query>[^#]*))?' .
'(#(?P<fragment>.*))?' .
Expand Down
19 changes: 19 additions & 0 deletions tests/Weew/Url/UrlParserTest.php
Expand Up @@ -50,6 +50,25 @@ public function test_parse() {
],
$parser->parse('http://name:pass@just.an.example.com:80/products?sku=1234#price')
);

$parser = new UrlParser();

$this->assertEquals(
[
'protocol' => 'http',
'username' => 'name',
'password' => 'pass',
'subdomain' => 'just.an',
'domain' => 'example',
'tld' => 'com',
'port' => '80',
'path' => null,
'query' => 'sku=1234',
'fragment' => 'price',
'host' => 'just.an.example.com',
],
$parser->parse('http://name:pass@just.an.example.com:80?sku=1234#price')
);
}

public function test_parse_host_removes_empty_strings() {
Expand Down
6 changes: 3 additions & 3 deletions tests/Weew/Url/UrlTest.php
Expand Up @@ -8,8 +8,8 @@
use Weew\Url\UrlQuery;

class UrlTest extends PHPUnit_Framework_TestCase {
private $url = 'http://name:pass@just.an.example.com:80/products?sku=12+34#price';
private $encodedUrl = 'http://name:pass@just.an.example.com:80/products?sku=12%2B34#price';
private $url = 'http://name:pass@just.an.example.com:80/products?sku=12+34 5#price';
private $encodedUrl = 'http://name:pass@just.an.example.com:80/products?sku=12%2B34%205#price';

public function test_get_and_set_segments() {
$url = new Url();
Expand Down Expand Up @@ -151,7 +151,7 @@ private function check_url(IUrl $url) {
$this->assertEquals('just.an', $url->getSubdomain());
$this->assertEquals('80', $url->getPort());
$this->assertEquals('/products', $url->getPath());
$this->assertEquals('sku=12+34', $url->getQuery()->toString(false));
$this->assertEquals('sku=12+34 5', $url->getQuery()->toString(false));
$this->assertEquals('price', $url->getFragment());
}

Expand Down

0 comments on commit 117be15

Please sign in to comment.