@av2k opened this Pull Request on November 12th 2014

Make URL recognition more conformant with RFC3986 and RFC1738 network-path references (URI beginning with a doubleslash).

When used with WP-Piwik in a Wordpress installation that uses such network-path references like '//domain' as base URI, Piwik does't recognize such a URI as valid, consequently putting a "http://" in front of it, resulting in a 'http:////domain' pattern which confuses the WP-Piwik plugin, resulting in multiple rewrites and creations of new sites.

@mnapoli commented on November 12th 2014 Contributor

Thanks, can you add any test to cover that?

Tests for this class are in UrlHelperTest here.

@mattab commented on November 17th 2014 Member

@av2k the new test is not passing:

1) Piwik\Tests\Unit\Core_UrlHelperTest::test_getHostFromUrl
Failed asserting that null matches expected 'localhost'.
@mattab commented on November 28th 2014 Member

Hi @av2k ping

@av2k commented on November 28th 2014


thanks for your ping. Unfortunately, I can't reproduce the issue.

The test method does this:

$this->assertEquals('localhost', UrlHelper::getHostFromUrl('http://localhost'));
$this->assertEquals('localhost', UrlHelper::getHostFromUrl('http://localhost/path'));
$this->assertEquals('localhost', UrlHelper::getHostFromUrl('localhost/path'));
$this->assertEquals('localhost', UrlHelper::getHostFromUrl('//localhost/path'));
$this->assertEquals('sub.localhost', UrlHelper::getHostFromUrl('sub.localhost/path'));
$this->assertEquals('sub.localhost', UrlHelper::getHostFromUrl('http://sub.localhost/path/?query=test'));

When I execute the method manually I get the expected results:

echo getHostFromUrl('http://localhost') . "\n";
echo getHostFromUrl('http://localhost/path') . "\n";
echo getHostFromUrl('localhost/path') . "\n";
echo getHostFromUrl('//localhost/path') . "\n";
echo getHostFromUrl('sub.localhost/path') . "\n";
echo getHostFromUrl('http://sub.localhost/path/?query=test') . "\n";


@mattab commented on December 3rd 2014 Member

Hi @av2k It was actually expected because parse_url is buggy on 5.3 and it was fixed in 5.4.7 see dfe30d91844677c2c41f2bbc63f933c116dbe52a

This Pull Request was closed on December 2nd 2014
Powered by GitHub Issue Mirror