Skip to content

Commit 5a934e9

Browse files
authored
fix: escape <textarea value={...}> attribute properly (#8434)
1 parent 3806977 commit 5a934e9

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/compiler/compile/render_ssr/handlers/shared/get_attribute_value.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ export function get_class_attribute_value(attribute: Attribute): ESTreeExpressio
1919
export 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, '&quot;')) 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
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
html: '<textarea></textarea>',
3+
ssrHtml: '<textarea>test\'"&gt;&lt;/textarea&gt;&lt;script&gt;alert(\'BIM\');&lt;/script&gt;</textarea>'
4+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<textarea value={`test'"></textarea><script>alert('BIM');</script>`} />

0 commit comments

Comments
 (0)