From d6ff0a75ab02d7c64f51ec8c21cb7819ae484158 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 10 Nov 2021 16:24:50 -0600 Subject: [PATCH] fix: attribute serialization --- packages/astro/src/runtime/server/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index ea4a50ed9a79..2a5543d498c4 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -208,6 +208,8 @@ export function createAstro(fileURLStr: string, site: string): TopLevelAstro { }; } +const toAttributeString = (value: any) => String(value).replace(/&/g, '&').replace(/"/g, '"') + // A helper used to turn expressions into attribute key/value export function addAttribute(value: any, key: string) { if (value == null || value === false) { @@ -216,10 +218,10 @@ export function addAttribute(value: any, key: string) { // support "class" from an expression passed into an element (#782) if (key === 'class:list') { - return ` ${key.slice(0, -5)}="${serializeListValue(value)}"`; + return ` ${key.slice(0, -5)}="${toAttributeString(serializeListValue(value))}"`; } - return ` ${key}="${value}"`; + return ` ${key}="${toAttributeString(value)}"`; } // Adds support for `