From d11dd552dbde181cd49652188521f4b5f6cad2f8 Mon Sep 17 00:00:00 2001 From: Pham Huy Hoang Date: Fri, 3 Mar 2023 09:09:52 +0700 Subject: [PATCH] injections(html): fix faulty css/js injections Group queries to reduce duplicate injection tree use only regex --- queries/html_tags/injections.scm | 34 ++++--------------- .../injections/html/test-html-injections.html | 4 +++ .../injections/vue/test-vue-injections.vue | 6 ++++ 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/queries/html_tags/injections.scm b/queries/html_tags/injections.scm index c29619281..5f0719c64 100644 --- a/queries/html_tags/injections.scm +++ b/queries/html_tags/injections.scm @@ -1,22 +1,12 @@ ; -( - (style_element - (start_tag - (tag_name) .) - (raw_text) @css) -) - ; ; Add "lang" to predicate check so that vue/svelte can inherit this ; without having this element being captured twice ( (style_element - (start_tag - (attribute - (attribute_name) @_no_set_type)) - (raw_text) @css) - (#not-any-of? @_no_set_type "type" "lang") -) + (start_tag) @_no_type_lang + (#not-match? @_no_type_lang "\\s(lang|type)\\s*\\=") + (raw_text) @css)) ( (style_element @@ -30,22 +20,12 @@ ) ; -( - (script_element - (start_tag - (tag_name) .) - (raw_text) @javascript) -) - ; ( (script_element - (start_tag - (attribute - (attribute_name) @_no_set_type)) - (raw_text) @javascript) - (#not-any-of? @_no_set_type "type" "lang") -) + (start_tag) @_no_type_lang + (#not-match? @_no_type_lang "\\s(lang|type)\\s*\\=") + (raw_text) @javascript)) ( (script_element @@ -55,7 +35,7 @@ (quoted_attribute_value (attribute_value) @_javascript))) (raw_text) @javascript) (#eq? @_type "type") - (#eq? @_javascript "text/javascript") + (#any-of? @_javascript "text/javascript" "module") ) ((attribute diff --git a/tests/query/injections/html/test-html-injections.html b/tests/query/injections/html/test-html-injections.html index 4449923c6..348d901ca 100644 --- a/tests/query/injections/html/test-html-injections.html +++ b/tests/query/injections/html/test-html-injections.html @@ -19,6 +19,10 @@ + + + +
Test div to test css injections for style attributes diff --git a/tests/query/injections/vue/test-vue-injections.vue b/tests/query/injections/vue/test-vue-injections.vue index 4cb4ae215..b0df16071 100644 --- a/tests/query/injections/vue/test-vue-injections.vue +++ b/tests/query/injections/vue/test-vue-injections.vue @@ -17,6 +17,9 @@ + + + @@ -26,3 +29,6 @@ + + +