diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2014-04-22 20:09:55 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2014-04-22 20:09:55 +0200 |
commit | f07180639c5af149447bc573db58ee130575369e (patch) | |
tree | 99f6f77b16f399c9afb1d2b642a89f29b83c06dc /tests/lib/util.php | |
parent | c1c2f2c49e4d30a7bd039837661af143054b6769 (diff) | |
download | nextcloud-server-f07180639c5af149447bc573db58ee130575369e.tar.gz nextcloud-server-f07180639c5af149447bc573db58ee130575369e.zip |
Add unit tests for arrays and "
OC_Util::sanitizeHTML() also supports array but we actually had no unit test for it. Additionally this commit introduces a test for escaping " into "
Diffstat (limited to 'tests/lib/util.php')
-rw-r--r-- | tests/lib/util.php | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/tests/lib/util.php b/tests/lib/util.php index ee336aa1118..20f2f7bbeab 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -43,15 +43,33 @@ class Test_Util extends PHPUnit_Framework_TestCase { } function testSanitizeHTML() { + $badArray = array( + 'While it is unusual to pass an array', + 'this function actually <blink>supports</blink> it.', + 'And therefore there needs to be a <script>alert("Unit"+\'test\')</script> for it!' + ); + $goodArray = array( + 'While it is unusual to pass an array', + 'this function actually <blink>supports</blink> it.', + 'And therefore there needs to be a <script>alert("Unit"+'test')</script> for it!' + ); + $result = OC_Util::sanitizeHTML($badArray); + $this->assertEquals($goodArray, $result); + + $badString = '<img onload="alert(1)" />'; + $result = OC_Util::sanitizeHTML($badString); + $this->assertEquals('<img onload="alert(1)" />', $result); + $badString = "<script>alert('Hacked!');</script>"; $result = OC_Util::sanitizeHTML($badString); - $this->assertEquals("<script>alert('Hacked!');</script>", $result); + $this->assertEquals('<script>alert('Hacked!');</script>', $result); - $goodString = "This is an harmless string."; + $goodString = 'This is a good string without HTML.'; $result = OC_Util::sanitizeHTML($goodString); - $this->assertEquals("This is an harmless string.", $result); - } - + $this->assertEquals('This is a good string without HTML.', $result); +} + + function testEncodePath(){ $component = '/§#@test%&^ä/-child'; $result = OC_Util::encodePath($component); |