Leave Alone

Strip parentBut keep children in order
', '

Leave Alone

Strip parentBut keep children in order', 'Non-whitelisted elements are stripped, but children are kept' ), array( 'p,strong', '
A B
Nested elements are still filtered
C
D
', 'A B Nested elements are still filtered C D', 'Non-whitelisted elements are stripped even when children of non-whitelisted elements' ), array( 'p', '

Keep

', '

Keep

', 'Non-whitelisted script elements are totally stripped, including any children' ), array( 'p[id]', '

Test

', '

Test

', 'Non-whitelisted attributes are stripped' ), array( 'p[default1=default1|default2=default2|force1:force1|force2:force2]', '

Test

', '

Test

', 'Default attributes are set when not present in input, forced attributes are always set' ), array( 'a[href|target|rel]', 'Test', 'Test', 'noopener rel attribute is added when target attribute is set' ), array( 'a[href|target|rel]', 'Test', 'Test', 'noopener rel attribute is added when target is _top instead of _blank' ), array( 'a[href|target|rel]', 'Test', 'Test', 'noopener rel attribute is removed when target is not set' ), array( 'a[href|target|rel]', 'Test', 'Test', 'noopener rel attribute is removed when link_rel_value is an empty string' ), array( 'a[href|target|rel]', 'Test', 'Test', 'noopener rel attribute is unchanged when link_rel_value is null' ), ); $config = HTMLEditorConfig::get('htmleditorsanitisertest'); foreach ($tests as $test) { list($validElements, $input, $output, $desc) = $test; $config->setOptions(array('valid_elements' => $validElements)); $sanitiser = new HtmlEditorSanitiser($config); $value = 'noopener noreferrer'; if (strpos($desc, 'link_rel_value is an empty string') !== false) { $value = ''; } elseif (strpos($desc, 'link_rel_value is null') !== false) { $value = null; } Config::inst()->set(HTMLEditorSanitiser::class, 'link_rel_value', $value); $htmlValue = HTMLValue::create($input); $sanitiser->sanitise($htmlValue); $this->assertEquals($output, $htmlValue->getContent(), $desc); } } }