mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-09 23:57:03 +02:00
[1.2.0] Added percent encoding normalization
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@509 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -4,7 +4,6 @@ require_once 'HTMLPurifier/AttrDefHarness.php';
|
||||
require_once 'HTMLPurifier/AttrDef/URI.php';
|
||||
|
||||
// WARNING: INCOMPLETE UNIT TESTS!
|
||||
// we are currently abstaining percent-encode fixing unit tests
|
||||
// we also need to test all the configuration directives defined by this class
|
||||
|
||||
// http: is returned quite often when a URL is invalid. We have to change
|
||||
@@ -83,10 +82,11 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
|
||||
// %5 - prematurely terminated, encode %
|
||||
// %FC - u with umlaut, correct
|
||||
// note that Apache doesn't do such fixing, rather, it just claims
|
||||
// that the browser sent a "Bad Request".
|
||||
//$uri[6] = 'http://www.example.com/%56%fc%GJ%5%FC';
|
||||
//$components[6] = array('www.example.com', '/V%FC%25GJ%255%FC', null, null);
|
||||
//$expect_uri[6] = 'http://www.example.com/V%FC%25GJ%255%FC';
|
||||
// that the browser sent a "Bad Request". See PercentEncoder.php
|
||||
// for more details
|
||||
$uri[6] = 'http://www.example.com/%56%fc%GJ%5%FC';
|
||||
$components[6] = array(null, 'www.example.com', null, '/V%FC%25GJ%255%FC', null);
|
||||
$expect_uri[6] = 'http://www.example.com/V%FC%25GJ%255%FC';
|
||||
|
||||
// test IPv4 address (behavior may vary with configuration)
|
||||
$uri[7] = 'http://192.0.34.166/';
|
||||
|
42
tests/HTMLPurifier/PercentEncoderTest.php
Normal file
42
tests/HTMLPurifier/PercentEncoderTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/PercentEncoder.php';
|
||||
|
||||
class HTMLPurifier_PercentEncoderTest extends UnitTestCase
|
||||
{
|
||||
|
||||
var $PercentEncoder;
|
||||
var $func;
|
||||
|
||||
function setUp() {
|
||||
$this->PercentEncoder = new HTMLPurifier_PercentEncoder();
|
||||
$this->func = '';
|
||||
}
|
||||
|
||||
function assertDecode($string, $expect = true) {
|
||||
if ($expect === true) $expect = $string;
|
||||
$this->assertEqual($this->PercentEncoder->{$this->func}($string), $expect);
|
||||
}
|
||||
|
||||
function test_normalize() {
|
||||
$this->func = 'normalize';
|
||||
|
||||
$this->assertDecode('Aw.../-$^8'); // no change
|
||||
$this->assertDecode('%41%77%7E%2D%2E%5F', 'Aw~-._'); // decode unreserved chars
|
||||
$this->assertDecode('%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D'); // preserve reserved chars
|
||||
$this->assertDecode('%2b', '%2B'); // normalize to uppercase
|
||||
$this->assertDecode('%2B2B%3A3A'); // extra text
|
||||
$this->assertDecode('%2b2B%4141', '%2B2BA41'); // extra text, with normalization
|
||||
$this->assertDecode('%', '%25'); // normalize stray percent sign
|
||||
$this->assertDecode('%5%25', '%255%25'); // permaturely terminated encoding
|
||||
$this->assertDecode('%GJ', '%25GJ'); // invalid hexadecimal chars
|
||||
|
||||
// contested behavior, if this changes, we'll also have to have
|
||||
// outbound encoding
|
||||
$this->assertDecode('%FC'); // not reserved or unreserved, preserve
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user