Typofix.
[htmlpurifier.git] / tests / HTMLPurifier / PercentEncoderTest.php
blobfa969de136a93def41a42d47d0524a66b69f1246
1 <?php
3 class HTMLPurifier_PercentEncoderTest extends HTMLPurifier_Harness
6 protected $PercentEncoder;
7 protected $func;
9 function setUp() {
10 $this->PercentEncoder = new HTMLPurifier_PercentEncoder();
11 $this->func = '';
14 function assertDecode($string, $expect = true) {
15 if ($expect === true) $expect = $string;
16 $this->assertIdentical($this->PercentEncoder->{$this->func}($string), $expect);
19 function test_normalize() {
20 $this->func = 'normalize';
22 $this->assertDecode('Aw.../-$^8'); // no change
23 $this->assertDecode('%41%77%7E%2D%2E%5F', 'Aw~-._'); // decode unreserved chars
24 $this->assertDecode('%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D'); // preserve reserved chars
25 $this->assertDecode('%2b', '%2B'); // normalize to uppercase
26 $this->assertDecode('%2B2B%3A3A'); // extra text
27 $this->assertDecode('%2b2B%4141', '%2B2BA41'); // extra text, with normalization
28 $this->assertDecode('%', '%25'); // normalize stray percent sign
29 $this->assertDecode('%5%25', '%255%25'); // permaturely terminated encoding
30 $this->assertDecode('%GJ', '%25GJ'); // invalid hexadecimal chars
32 // contested behavior, if this changes, we'll also have to have
33 // outbound encoding
34 $this->assertDecode('%FC'); // not reserved or unreserved, preserve
38 function assertEncode($string, $expect = true, $preserve = false) {
39 if ($expect === true) $expect = $string;
40 $encoder = new HTMLPurifier_PercentEncoder($preserve);
41 $result = $encoder->encode($string);
42 $this->assertIdentical($result, $expect);
45 function test_encode_noChange() {
46 $this->assertEncode('abc012-_~.');
49 function test_encode_encode() {
50 $this->assertEncode('>', '%3E');
53 function test_encode_preserve() {
54 $this->assertEncode('<>', '<%3E', '<');
57 function test_encode_low() {
58 $this->assertEncode("\1", '%01');
63 // vim: et sw=4 sts=4