Skip to content

Commit

Permalink
fix: attribute serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Moore committed Nov 10, 2021
1 parent def7bc2 commit d6ff0a7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 `<Component {...value} />
Expand Down

0 comments on commit d6ff0a7

Please sign in to comment.