File tree Expand file tree Collapse file tree 3 files changed +12
-1
lines changed
src/compiler/compile/render_ssr/handlers/shared
test/runtime/samples/attribute-escape Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -19,11 +19,17 @@ export function get_class_attribute_value(attribute: Attribute): ESTreeExpressio
19
19
export function get_attribute_value ( attribute : Attribute ) : ESTreeExpression {
20
20
if ( attribute . chunks . length === 0 ) return x `""` ;
21
21
22
+ /**
23
+ * For value attribute of textarea, it will render as child node of `<textarea>` element.
24
+ * Therefore, we need to escape as content (not attribute).
25
+ */
26
+ const is_textarea_value = attribute . parent . name . toLowerCase ( ) === 'textarea' && attribute . name . toLowerCase ( ) === 'value' ;
27
+
22
28
return attribute . chunks
23
29
. map ( ( chunk ) => {
24
30
return chunk . type === 'Text'
25
31
? string_literal ( chunk . data . replace ( regex_double_quotes , '"' ) ) as ESTreeExpression
26
- : x `@escape(${ chunk . node } , true)` ;
32
+ : x `@escape(${ chunk . node } , ${ is_textarea_value ? 'false' : ' true' } )` ;
27
33
} )
28
34
. reduce ( ( lhs , rhs ) => x `${ lhs } + ${ rhs } ` ) ;
29
35
}
Original file line number Diff line number Diff line change
1
+ export default {
2
+ html : '<textarea></textarea>' ,
3
+ ssrHtml : '<textarea>test\'"></textarea><script>alert(\'BIM\');</script></textarea>'
4
+ } ;
Original file line number Diff line number Diff line change
1
+ <textarea value ={` test'"></textarea><script>alert('BIM');</script> ` } />
You can’t perform that action at this time.
0 commit comments