From 29d4695fc769e995e98bc538d4325e5679ec0298 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 20 Nov 2020 08:43:05 -0500 Subject: [PATCH] boolean argument --- .../compile/render_ssr/handlers/shared/get_attribute_value.ts | 4 ++-- src/runtime/internal/ssr.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/compile/render_ssr/handlers/shared/get_attribute_value.ts b/src/compiler/compile/render_ssr/handlers/shared/get_attribute_value.ts index 9efb086854..d62b2d14e9 100644 --- a/src/compiler/compile/render_ssr/handlers/shared/get_attribute_value.ts +++ b/src/compiler/compile/render_ssr/handlers/shared/get_attribute_value.ts @@ -9,7 +9,7 @@ export function get_class_attribute_value(attribute: Attribute): ESTreeExpressio // handle special case — `class={possiblyUndefined}` with scoped CSS if (attribute.chunks.length === 2 && (attribute.chunks[1] as Text).synthetic) { const value = (attribute.chunks[0] as Expression).node; - return x`@escape(@null_to_empty(${value}), 1) + "${(attribute.chunks[1] as Text).data}"`; + return x`@escape(@null_to_empty(${value}), true) + "${(attribute.chunks[1] as Text).data}"`; } return get_attribute_value(attribute); @@ -22,7 +22,7 @@ export function get_attribute_value(attribute: Attribute): ESTreeExpression { .map((chunk) => { return chunk.type === 'Text' ? string_literal(chunk.data.replace(/"/g, '"')) as ESTreeExpression - : x`@escape(${chunk.node}, 1)`; + : x`@escape(${chunk.node}, true)`; }) .reduce((lhs, rhs) => x`${lhs} + ${rhs}`); } diff --git a/src/runtime/internal/ssr.ts b/src/runtime/internal/ssr.ts index 92e6a923b8..5d321abee4 100644 --- a/src/runtime/internal/ssr.ts +++ b/src/runtime/internal/ssr.ts @@ -41,10 +41,10 @@ const escapes = { '<': '<' }; -export function escape(html: string, attr: 0 | 1 = 0) { +export function escape(html: string, is_attr = false) { if (typeof html !== 'string') return html; - const pattern = attr ? ATTR_REGEX : CONTENT_REGEX; + const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX; pattern.lastIndex = 0; let escaped = '';