@@ -98,6 +98,15 @@ public static function get_css_file_links2() {
9898 );
9999 }
100100
101+ public static function get_css_with_special_characters () {
102+ return [
103+ [ '.button { &:hover { background-color: #000; } } ' ],
104+ [ '@media (width < 600px) { .button { background-color: #0f0; } } ' ],
105+ [ '@media (width >= 600px) { .button { background-color: #f00; } } ' ],
106+ [ '.quote { font-family: "Comic Sans MS", cursive; } ' ],
107+ [ "a[target='_blank'] { color: blue; } " ],
108+ ];
109+ }
101110
102111 //
103112 //
@@ -452,6 +461,27 @@ public function test_add_css_to_head_with_just_css( $expected = false ) {
452461 return $ out ;
453462 }
454463
464+ /**
465+ * @dataProvider get_css_with_special_characters
466+ */
467+ public function test_add_css_allows_valid_css_characters ( $ css ) {
468+ $ this ->set_option ( [ 'css ' => $ css , 'files ' => [] ] );
469+ $ this ->test_turn_on_admin ();
470+
471+ $ this ->assertStringContainsString ( $ css , $ this ->get_action_output () );
472+ }
473+
474+ public function test_add_css_prevents_markup_injection () {
475+ $ injection = '<script>alert("Hello, world!");</script> ' ;
476+ $ css = $ this ->add_css ( $ injection , '' );
477+
478+ $ this ->set_option ( [ 'css ' => $ css , 'files ' => [] ] );
479+ $ this ->test_turn_on_admin ();
480+
481+ $ this ->assertStringNotContainsString ( $ injection , $ this ->get_action_output () );
482+ $ this ->assertStringContainsString ( str_replace ( '< ' , '< ' , $ injection ), $ this ->get_action_output () );
483+ }
484+
455485 public function test_add_css_to_head_with_just_files ( $ expected = false ) {
456486 // Examples of different types of references.
457487 $ files = array (
0 commit comments