diff options
author | friendica <info@friendica.com> | 2012-05-12 17:57:41 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2012-07-18 20:40:31 +1000 |
commit | 7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a (patch) | |
tree | a9c3d91209cff770bb4b613b1b95e61a7bbc5a2b /lib/htmlpurifier/tests/HTMLPurifier/PercentEncoderTest.php | |
parent | cd727cb26b78a1dade09d510b071446898477356 (diff) | |
download | volse-hubzilla-7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a.tar.gz volse-hubzilla-7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a.tar.bz2 volse-hubzilla-7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a.zip |
some important stuff we'll need
Diffstat (limited to 'lib/htmlpurifier/tests/HTMLPurifier/PercentEncoderTest.php')
-rw-r--r-- | lib/htmlpurifier/tests/HTMLPurifier/PercentEncoderTest.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/PercentEncoderTest.php b/lib/htmlpurifier/tests/HTMLPurifier/PercentEncoderTest.php new file mode 100644 index 000000000..fa969de13 --- /dev/null +++ b/lib/htmlpurifier/tests/HTMLPurifier/PercentEncoderTest.php @@ -0,0 +1,63 @@ +<?php + +class HTMLPurifier_PercentEncoderTest extends HTMLPurifier_Harness +{ + + protected $PercentEncoder; + protected $func; + + function setUp() { + $this->PercentEncoder = new HTMLPurifier_PercentEncoder(); + $this->func = ''; + } + + function assertDecode($string, $expect = true) { + if ($expect === true) $expect = $string; + $this->assertIdentical($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 + + } + + function assertEncode($string, $expect = true, $preserve = false) { + if ($expect === true) $expect = $string; + $encoder = new HTMLPurifier_PercentEncoder($preserve); + $result = $encoder->encode($string); + $this->assertIdentical($result, $expect); + } + + function test_encode_noChange() { + $this->assertEncode('abc012-_~.'); + } + + function test_encode_encode() { + $this->assertEncode('>', '%3E'); + } + + function test_encode_preserve() { + $this->assertEncode('<>', '<%3E', '<'); + } + + function test_encode_low() { + $this->assertEncode("\1", '%01'); + } + +} + +// vim: et sw=4 sts=4 |