8000 fix: escape <textarea value={...}> attribute properly by baseballyama · Pull Request #8434 · sveltejs/svelte · GitHub
[go: up one dir, main page]

Skip to content

fix: escape <textarea value={...}> attribute properly #8434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
baseballyama committed Mar 30, 2023
commit 1ed69fa0f2b54eb1a2b4931e9c4227ea7c09d720
4 changes: 2 additions & 2 deletions src/compiler/compile/render_ssr/handlers/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, true);
node_contents = get_attribute_value(attribute);
} else if (attribute.is_true) {
args.push(x`{ ${attr_name}: true }`);
} else if (
Expand All @@ -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, true);
node_contents = get_attribute_value(attribute);
} else if (attribute.is_true) {
renderer.add_string(` ${attr_name}`);
} else if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ export function get_class_attribute_value(attribute: Attribute): ESTreeExpressio
return get_attribute_value(attribute);
}

/**
* 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 {

export function get_attribute_value(attribute: Attribute): ESTreeExpression {
if (attribute.chunks.length === 0) return x`""`;

/**
* For value attribute of textarea, it will render as child node of `<textarea>` element.
* Therefore, we need to escape as content (not attribute).
*/
const is_textarea_value = attribute.parent.name.toLowerCase() === 'textarea' && attribute.name.toLowerCase() === 'value';

return attribute.chunks
.map((chunk) => {
return chunk.type === 'Text'
Expand Down
0