File tree Expand file tree Collapse file tree 5 files changed +100
-1
lines changed
Expand file tree Collapse file tree 5 files changed +100
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * PHP Domain Parser: Public Suffix List based URL parsing.
5+ *
6+ * @link http://github.com/jeremykendall/php-domain-parser for the canonical source repository
7+ *
8+ * @copyright Copyright (c) 2014 Jeremy Kendall (http://about.me/jeremykendall)
9+ * @license http://github.com/jeremykendall/php-domain-parser/blob/master/LICENSE MIT License
10+ */
11+ namespace Pdp \Exception ;
12+
13+ interface PdpException
14+ {
15+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * PHP Domain Parser: Public Suffix List based URL parsing.
5+ *
6+ * @link http://github.com/jeremykendall/php-domain-parser for the canonical source repository
7+ *
8+ * @copyright Copyright (c) 2014 Jeremy Kendall (http://about.me/jeremykendall)
9+ * @license http://github.com/jeremykendall/php-domain-parser/blob/master/LICENSE MIT License
10+ */
11+ namespace Pdp \Exception ;
12+
13+ /**
14+ * Should be thrown when pdp_parse_url() return false.
15+ *
16+ * Exception name based on the PHP documentation: "On seriously malformed URLs,
17+ * parse_url() may return FALSE."
18+ *
19+ * @see http://php.net/parse_url
20+ */
21+ class SeriouslyMalformedUrlException extends \InvalidArgumentException implements PdpException
22+ {
23+ /**
24+ * Public constructor
25+ *
26+ * @param string $malformedUrl URL that caused pdp_parse_url() to return false
27+ * @param int $code The Exception code
28+ * @param \Exception $previous The previous exception used for the exception chaining
29+ */
30+ public function __construct ($ malformedUrl = "" , $ code = 0 , $ previous = null )
31+ {
32+ $ message = sprintf ('"%s" is one seriously malformed url. ' , $ malformedUrl );
33+ parent ::__construct ($ message , $ code , $ previous );
34+ }
35+ }
Original file line number Diff line number Diff line change @@ -80,7 +80,9 @@ public function __construct(
8080 $ query ,
8181 $ fragment
8282 ) {
83- $ this ->scheme = mb_strtolower ($ scheme , 'UTF-8 ' );
83+ // Ensure scheme is either a legit scheme or null, never an empty string.
84+ // @see https://github.com/jeremykendall/php-domain-parser/issues/53
85+ $ this ->scheme = mb_strtolower ($ scheme , 'UTF-8 ' ) ?: null ;
8486 $ this ->user = $ user ;
8587 $ this ->pass = $ pass ;
8688 $ this ->host = $ host ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Pdp \Exception ;
4+
5+ class SeriouslyMalformedUrlExceptionTest extends \PHPUnit_Framework_TestCase
6+ {
7+ public function testInstanceOfPdpException ()
8+ {
9+ $ this ->assertInstanceOf (
10+ 'Pdp\Exception\PdpException ' ,
11+ new SeriouslyMalformedUrlException ()
12+ );
13+ }
14+
15+ public function testInstanceOfInvalidArgumentException ()
16+ {
17+ $ this ->assertInstanceOf (
18+ 'InvalidArgumentException ' ,
19+ new SeriouslyMalformedUrlException ()
20+ );
21+ }
22+
23+ public function testMessage ()
24+ {
25+ $ url = 'http:///example.com ' ;
26+ $ this ->setExpectedException (
27+ 'Pdp\Exception\SeriouslyMalformedUrlException ' ,
28+ sprintf ('"%s" is one seriously malformed url. ' , $ url )
29+ );
30+
31+ throw new SeriouslyMalformedUrlException ($ url );
32+ }
33+ }
Original file line number Diff line number Diff line change @@ -181,4 +181,18 @@ public function testSchemeAlwaysConvertedToLowerCasePerRFC3986()
181181 $ url = $ this ->parser ->parseUrl ($ spec );
182182 $ this ->assertEquals ($ expected , $ url ->__toString ());
183183 }
184+
185+ /**
186+ * Scheme should return null when scheme is not provided.
187+ *
188+ * @group issue53
189+ *
190+ * @see https://github.com/jeremykendall/php-domain-parser/issues/53
191+ */
192+ public function testSchemeReturnsNullIfNotProvidedToParser ()
193+ {
194+ $ spec = 'google.com ' ;
195+ $ url = $ this ->parser ->parseUrl ($ spec );
196+ $ this ->assertNull ($ url ->getScheme ());
197+ }
184198}
You can’t perform that action at this time.
0 commit comments