File tree Expand file tree Collapse file tree 3 files changed +34
-9
lines changed Expand file tree Collapse file tree 3 files changed +34
-9
lines changed Original file line number Diff line number Diff line change 2121class SeriouslyMalformedUrlException extends \InvalidArgumentException implements PdpException
2222{
2323 /**
24- * Public constructor
24+ * Public constructor.
2525 *
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
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
2929 */
30- public function __construct ($ malformedUrl = "" , $ code = 0 , $ previous = null )
30+ public function __construct ($ malformedUrl = '' , $ code = 0 , $ previous = null )
3131 {
3232 $ message = sprintf ('"%s" is one seriously malformed url. ' , $ malformedUrl );
3333 parent ::__construct ($ message , $ code , $ previous );
Original file line number Diff line number Diff line change 1010 */
1111namespace Pdp ;
1212
13+ use Pdp \Exception \SeriouslyMalformedUrlException ;
1314use Pdp \Uri \Url ;
1415use Pdp \Uri \Url \Host ;
1516
@@ -63,6 +64,7 @@ public function __construct(PublicSuffixList $publicSuffixList)
6364 */
6465 public function parseUrl ($ url )
6566 {
67+ $ rawUrl = $ url ;
6668 $ elem = array (
6769 'scheme ' => null ,
6870 'user ' => null ,
@@ -83,7 +85,7 @@ public function parseUrl($url)
8385 $ parts = pdp_parse_url ($ url );
8486
8587 if ($ parts === false ) {
86- throw new \ InvalidArgumentException ( sprintf ( ' Invalid url %s ' , $ url ) );
88+ throw new SeriouslyMalformedUrlException ( $ rawUrl );
8789 }
8890
8991 if ($ parts ['scheme ' ] === 'php-lt-5.4.7-hack ' ) {
Original file line number Diff line number Diff line change @@ -49,13 +49,36 @@ public function testIsSuffixValidTrue()
4949 * @covers ::pdp_parse_url
5050 */
5151 public function testParseBadUrlThrowsInvalidArgumentException ()
52+ {
53+ $ url = 'http:///example.com ' ;
54+
55+ $ this ->setExpectedException (
56+ 'Pdp\Exception\SeriouslyMalformedUrlException ' ,
57+ sprintf ('"%s" is one seriously malformed url. ' , $ url )
58+ );
59+
60+ $ this ->parser ->parseUrl ($ url );
61+ }
62+
63+ /**
64+ * If an empty string is passed to the parser then the hacky scheme from
65+ * issue 49 should not appear in the Exception message.
66+ *
67+ * @group issue54
68+ *
69+ * @see https://github.com/jeremykendall/php-domain-parser/issues/54
70+ *
71+ * @covers Pdp\Parser::parseUrl()
72+ * @covers ::pdp_parse_url
73+ */
74+ public function testParseEmptyStringThrowsInvalidArgumentExceptionWithoutWackySchemeInMessage ()
5275 {
5376 $ this ->setExpectedException (
54- '\InvalidArgumentException ' ,
55- 'Invalid url http:///example.com '
77+ 'Pdp\Exception\SeriouslyMalformedUrlException ' ,
78+ '"" is one seriously malformed url. '
5679 );
5780
58- $ this ->parser ->parseUrl ('http:///example.com ' );
81+ $ this ->parser ->parseUrl ('' );
5982 }
6083
6184 /**
You can’t perform that action at this time.
0 commit comments