Skip to content

Commit

Permalink
chore(ssr): use htmlEscape consistently (#5116)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Jan 9, 2025
1 parent fb5ef00 commit f080072
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/@lwc/ssr-runtime/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { getOwnPropertyNames, isNull, isString, isUndefined, DEFAULT_SSR_MODE } from '@lwc/shared';
import {
getOwnPropertyNames,
isNull,
isString,
isUndefined,
DEFAULT_SSR_MODE,
htmlEscape,
} from '@lwc/shared';
import { mutationTracker } from './mutation-tracker';
import { SYMBOL__GENERATE_MARKUP } from './lightning-element';
import type { LightningElement, LightningElementConstructor } from './lightning-element';
import type { Attributes, Properties } from './types';

const escapeAttrVal = (attrValue: string) =>
attrValue.replaceAll('&', '&').replaceAll('"', '"');

function renderAttrsPrivate(
instance: LightningElement,
attrs: Attributes,
Expand Down Expand Up @@ -58,7 +62,8 @@ function renderAttrsPrivate(
}
}

result += attrValue === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrValue)}"`;
result +=
attrValue === '' ? ` ${attrName}` : ` ${attrName}="${htmlEscape(attrValue, true)}"`;
}

// If we didn't render any `class` attribute, render one for the scope token(s)
Expand Down

0 comments on commit f080072

Please sign in to comment.