Skip to content

Commit 00bdb37

Browse files
committed
Do not prepend 'http' to URLs without schemes. #46.
Will no longer add 'http' to URLs parsed in the form of www.graphstory.com or //www.graphstory.com
1 parent bf41fb1 commit 00bdb37

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/Pdp/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function parseUrl($url)
6363
);
6464

6565
if (preg_match(self::SCHEME_PATTERN, $url) === 0) {
66-
$url = 'http://' . preg_replace('#^//#', '', $url, 1);
66+
$url = '//' . preg_replace('#^//#', '', $url, 1);
6767
}
6868

6969
$parts = pdp_parse_url($url);

tests/src/Pdp/ParserTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ public function testpdp_parse_urlCanReturnCorrectHost($url, $publicSuffix, $regi
153153
);
154154
}
155155

156+
/**
157+
* @group issue46
158+
*
159+
* Don't add a scheme to schemeless URLs
160+
*
161+
* @see https://github.com/jeremykendall/php-domain-parser/issues/46
162+
*/
163+
public function testDoNotPrependSchemeToSchemelessUrls()
164+
{
165+
$schemeless = 'www.graphstory.com';
166+
$expected = 'www.graphstory.com';
167+
$url = $this->parser->parseUrl($schemeless);
168+
$actual = $url->__toString();
169+
170+
$this->assertEquals($expected, $actual);
171+
172+
$schemeless = '//www.graphstory.com';
173+
$expected = 'www.graphstory.com';
174+
$url = $this->parser->parseUrl($schemeless);
175+
$actual = $url->__toString();
176+
177+
$this->assertEquals($expected, $actual);
178+
}
179+
156180
public function parseDataProvider()
157181
{
158182
return array(

tests/src/Pdp/Uri/UrlTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,20 @@ public function testFtpUrlToString()
128128
}
129129

130130
/**
131+
* This test fixes #29. It has been updated due to a change suggested in #46.
132+
* The original $expected value was 'http://яндекс.рф', as parsing would add
133+
* 'http://' to URLs that did not have a scheme. That behavior has been removed.
134+
* The new $expected result is 'яндекс.рф'.
135+
*
131136
* @group issue29
137+
* @group issue46
132138
* @see https://github.com/jeremykendall/php-domain-parser/issues/29
139+
* @see https://github.com/jeremykendall/php-domain-parser/issues/46
133140
*/
134141
public function testIdnToAscii()
135142
{
136143
$idn = 'Яндекс.РФ';
137-
$expected = 'http://яндекс.рф';
144+
$expected = 'яндекс.рф';
138145
$url = $this->parser->parseUrl($idn);
139146
$actual = $url->__toString();
140147

0 commit comments

Comments
 (0)