@@ -4122,4 +4122,56 @@ public function test_wp_scripts_doing_it_wrong_for_missing_dependencies() {
41224122 'Expected _doing_it_wrong() notice to indicate missing dependencies for enqueued script. '
41234123 );
41244124 }
4125+
4126+ /**
4127+ * @ticket TBD
4128+ * @covers ::wp_add_inline_script
4129+ */
4130+ public function test_gnarly_inline_script_requires_escaping () {
4131+ $ this ->add_html5_script_theme_support ();
4132+ wp_enqueue_script ( 'test-inline-script-after ' , 'http://example.org/script.js ' , array (), null );
4133+ $ javascript = <<<'JS'
4134+ var script;
4135+ 0</script/>0;'<!--';console.assert(1<script>=0);
4136+ JS;
4137+ wp_add_inline_script ( 'test-inline-script-after ' , $ javascript , 'after ' );
4138+ $ output = get_echo ( 'wp_print_scripts ' );
4139+ $ expected = <<<'HTML'
4140+ <script src="http://example.org/script.js" id="test-inline-script-after-js"></script>
4141+ <script id="test-inline-script-after-js-after">
4142+ var script;
4143+ 0</\u0073cript/>0;'<!--';console.assert(1<\u0073cript>=0);
4144+ //# sourceURL=test-inline-script-after-js-after
4145+ </script>
4146+ HTML;
4147+
4148+ $ this ->assertEqualHTML ( $ expected , $ output );
4149+ }
4150+
4151+ /**
4152+ * @ticket TBD
4153+ * @covers ::wp_add_inline_script
4154+ *
4155+ * @expectedIncorrectUsage wp_add_inline_script
4156+ */
4157+ public function test_gnarly_inline_script_requires_escaping_with_wrapper () {
4158+ $ this ->add_html5_script_theme_support ();
4159+ wp_enqueue_script ( 'test-inline-script-after ' , 'http://example.org/script.js ' , array (), null );
4160+ $ javascript = <<<'JS'
4161+ <script>
4162+ // Uh oh:</script>
4163+ </script>
4164+ JS;
4165+ wp_add_inline_script ( 'test-inline-script-after ' , $ javascript , 'after ' );
4166+ $ output = get_echo ( 'wp_print_scripts ' );
4167+ $ expected = <<<'HTML'
4168+ <script src="http://example.org/script.js" id="test-inline-script-after-js"></script>
4169+ <script id="test-inline-script-after-js-after">
4170+ // Uh oh:
4171+ //# sourceURL=test-inline-script-after-js-after
4172+ </script>
4173+ HTML;
4174+
4175+ $ this ->assertEqualHTML ( $ expected , $ output );
4176+ }
41254177}
0 commit comments