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 21
21
class SeriouslyMalformedUrlException extends \InvalidArgumentException implements PdpException
22
22
{
23
23
/**
24
- * Public constructor
24
+ * Public constructor.
25
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
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
29
*/
30
- public function __construct ($ malformedUrl = "" , $ code = 0 , $ previous = null )
30
+ public function __construct ($ malformedUrl = '' , $ code = 0 , $ previous = null )
31
31
{
32
32
$ message = sprintf ('"%s" is one seriously malformed url. ' , $ malformedUrl );
33
33
parent ::__construct ($ message , $ code , $ previous );
Original file line number Diff line number Diff line change 10
10
*/
11
11
namespace Pdp ;
12
12
13
+ use Pdp \Exception \SeriouslyMalformedUrlException ;
13
14
use Pdp \Uri \Url ;
14
15
use Pdp \Uri \Url \Host ;
15
16
@@ -63,6 +64,7 @@ public function __construct(PublicSuffixList $publicSuffixList)
63
64
*/
64
65
public function parseUrl ($ url )
65
66
{
67
+ $ rawUrl = $ url ;
66
68
$ elem = array (
67
69
'scheme ' => null ,
68
70
'user ' => null ,
@@ -83,7 +85,7 @@ public function parseUrl($url)
83
85
$ parts = pdp_parse_url ($ url );
84
86
85
87
if ($ parts === false ) {
86
- throw new \ InvalidArgumentException ( sprintf ( ' Invalid url %s ' , $ url ) );
88
+ throw new SeriouslyMalformedUrlException ( $ rawUrl );
87
89
}
88
90
89
91
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()
49
49
* @covers ::pdp_parse_url
50
50
*/
51
51
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 ()
52
75
{
53
76
$ this ->setExpectedException (
54
- '\InvalidArgumentException ' ,
55
- 'Invalid url http:///example.com '
77
+ 'Pdp\Exception\SeriouslyMalformedUrlException ' ,
78
+ '"" is one seriously malformed url. '
56
79
);
57
80
58
- $ this ->parser ->parseUrl ('http:///example.com ' );
81
+ $ this ->parser ->parseUrl ('' );
59
82
}
60
83
61
84
/**
You can’t perform that action at this time.
0 commit comments