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
1919export function get_attribute_value ( attribute : Attribute ) : ESTreeExpression {
2020 if ( attribute . chunks . length === 0 ) return x `""` ;
2121
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+
2228 return attribute . chunks
2329 . map ( ( chunk ) => {
2430 return chunk . type === 'Text'
2531 ? 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' } )` ;
2733 } )
2834 . reduce ( ( lhs , rhs ) => x `${ lhs } + ${ rhs } ` ) ;
2935}
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