now handle only textarea

pull/8434/head
baseballyama 3 years ago
parent ac10659ff8
commit aadda27bea

@ -63,7 +63,7 @@ export default function (node: Element, renderer: Renderer, options: RenderOptio
const attr_name = node.namespace === namespaces.foreign ? attribute.name : fix_attribute_casing(attribute.name);
const name = attribute.name.toLowerCase();
if (name === 'value' && node.name.toLowerCase() === 'textarea') {
node_contents = get_attribute_value(attribute);
node_contents = get_attribute_value(attribute, true);
} else if (attribute.is_true) {
args.push(x`{ ${attr_name}: true }`);
} else if (
@ -90,7 +90,7 @@ export default function (node: Element, renderer: Renderer, options: RenderOptio
const name = attribute.name.toLowerCase();
const attr_name = node.namespace === namespaces.foreign ? attribute.name : fix_attribute_casing(attribute.name);
if (name === 'value' && node.name.toLowerCase() === 'textarea') {
node_contents = get_attribute_value(attribute);
node_contents = get_attribute_value(attribute, true);
} else if (attribute.is_true) {
renderer.add_string(` ${attr_name}`);
} else if (

@ -16,14 +16,18 @@ export function get_class_attribute_value(attribute: Attribute): ESTreeExpressio
return get_attribute_value(attribute);
}
export function get_attribute_value(attribute: Attribute): ESTreeExpression {
/**
* For value attribute of textarea, it will render as child node of `<textarea>` element.
* Therefore, we need to escape as content (not attribute).
*/
export function get_attribute_value(attribute: Attribute, is_textarea_value = false): ESTreeExpression {
if (attribute.chunks.length === 0) return x`""`;
return attribute.chunks
.map((chunk) => {
return chunk.type === 'Text'
? string_literal(chunk.data.replace(regex_double_quotes, '&quot;')) as ESTreeExpression
: x`@escape(${chunk.node}, true)`;
: x`@escape(${chunk.node}, ${is_textarea_value ? 'false' : 'true'})`;
})
.reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
}

@ -69,7 +69,7 @@ export function merge_ssr_styles(style_attribute, style_directive) {
return style_object;
}
const ATTR_REGEX = /[&"<]/g;
const ATTR_REGEX = /[&"]/g;
const CONTENT_REGEX = /[&<]/g;
/**

Loading…
Cancel
Save