2007-08-01 14:55:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_URIParserTest extends HTMLPurifier_Harness
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
protected function assertParsing(
|
2007-08-01 14:55:09 +00:00
|
|
|
$uri, $scheme, $userinfo, $host, $port, $path, $query, $fragment, $config = null, $context = null
|
|
|
|
) {
|
|
|
|
$this->prepareCommon($config, $context);
|
|
|
|
$parser = new HTMLPurifier_URIParser();
|
|
|
|
$result = $parser->parse($uri, $config, $context);
|
2007-08-01 18:34:46 +00:00
|
|
|
$expect = new HTMLPurifier_URI($scheme, $userinfo, $host, $port, $path, $query, $fragment);
|
|
|
|
$this->assertEqual($result, $expect);
|
2007-08-01 14:55:09 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPercentNormalization()
|
|
|
|
{
|
2008-05-14 02:19:00 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'%G',
|
|
|
|
null, null, null, null, '%25G', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRegular()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http://www.example.com/webhp?q=foo#result2',
|
|
|
|
'http', null, 'www.example.com', null, '/webhp', 'q=foo', 'result2'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPortAndUsername()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http://user@authority.part:80/now/the/path?query#fragment',
|
|
|
|
'http', 'user', 'authority.part', 80, '/now/the/path', 'query', 'fragment'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPercentEncoding()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http://en.wikipedia.org/wiki/Clich%C3%A9',
|
|
|
|
'http', null, 'en.wikipedia.org', null, '/wiki/Clich%C3%A9', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testEmptyQuery()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http://www.example.com/?#',
|
|
|
|
'http', null, 'www.example.com', null, '/', '', null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testEmptyPath()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http://www.example.com',
|
|
|
|
'http', null, 'www.example.com', null, '', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testOpaqueURI()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'mailto:bob@example.com',
|
|
|
|
'mailto', null, null, null, 'bob@example.com', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2016-06-17 23:39:18 +00:00
|
|
|
public function testTelURI()
|
|
|
|
{
|
|
|
|
$this->assertParsing(
|
|
|
|
'tel:+1 (555) 555-5555',
|
|
|
|
'tel', null, null, null, '+1 (555) 555-5555', null, null
|
|
|
|
);
|
2022-11-24 21:31:20 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'tel:+1%20(555)%20555-5555',
|
|
|
|
'tel', null, null, null, '+1%20(555)%20555-5555', null, null
|
|
|
|
);
|
2016-06-17 23:39:18 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testIPv4Address()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http://192.0.34.166/',
|
|
|
|
'http', null, '192.0.34.166', null, '/', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testFakeIPv4Address()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http://333.123.32.123/',
|
|
|
|
'http', null, '333.123.32.123', null, '/', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testIPv6Address()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http://[2001:db8::7]/c=GB?objectClass?one',
|
|
|
|
'http', null, '[2001:db8::7]', null, '/c=GB', 'objectClass?one', null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testInternationalizedDomainName()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
"http://t\xC5\xABdali\xC5\x86.lv",
|
|
|
|
'http', null, "t\xC5\xABdali\xC5\x86.lv", null, '', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testInvalidPort()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http://example.com:foobar',
|
|
|
|
'http', null, 'example.com', null, '', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPathAbsolute()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http:/this/is/path',
|
|
|
|
'http', null, null, null, '/this/is/path', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPathRootless()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
// this should not be used but is allowed
|
|
|
|
$this->assertParsing(
|
|
|
|
'http:this/is/path',
|
|
|
|
'http', null, null, null, 'this/is/path', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPathEmpty()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'http:',
|
|
|
|
'http', null, null, null, '', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRelativeURI()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'/a/b',
|
|
|
|
null, null, null, null, '/a/b', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testMalformedTag()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
2008-05-14 02:19:00 +00:00
|
|
|
'http://www.example.com/>',
|
2007-08-01 14:55:09 +00:00
|
|
|
'http', null, 'www.example.com', null, '/', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testEmpty()
|
|
|
|
{
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'',
|
|
|
|
null, null, null, null, '', null, null
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testEmbeddedColon()
|
|
|
|
{
|
2013-04-16 20:46:00 +00:00
|
|
|
$this->assertParsing(
|
|
|
|
'{:test:}',
|
|
|
|
null, null, null, null, '{:test:}', null, null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-08-01 14:55:09 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|