Skip to content

Commit d01f0ae

Browse files
committed
fix(preview): consume complete custom element tag names
1 parent dbc94bb commit d01f0ae

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎apps/server/src/http.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ describe("generated HTML focus protection", () => {
366366
[ordinary, false, true],
367367
[`<div data-example="<style id='t3-theme'> >">édit</div>`, false, true],
368368
[`<div data-example='<style id="t3-theme">'>édit</div>`, false, true],
369+
[`<my-theme_card data-example="<style id='t3-theme'>">édit</my-theme_card>`, false, true],
369370
[`<style data-example="id='t3-theme'">body{color:red}</style>`, false, true],
370371
[generated, true, true],
371372
[generated, false, false],

‎packages/shared/src/htmlRender.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ describe("injectHtmlRenderFocusStyles", () => {
8989
`<div data-example="<style id='t3-theme'>"></div>`,
9090
`<div data-example='<style id="t3-theme">'></div>`,
9191
`<div data-example="> <style id='t3-theme'>"></div>`,
92+
`<my-theme_card data-example="<style id='t3-theme'>"></my-theme_card>`,
93+
`<my-theme.card data-example="<style id='t3-theme'>"></my-theme.card>`,
9294
`<style data-example="<style id='t3-theme'>">body{color:red}</style>`,
9395
`<style data-example="id='t3-theme'">body{color:red}</style>`,
9496
`<style data-id="t3-theme">body{color:red}</style>`,
@@ -104,6 +106,8 @@ describe("injectHtmlRenderFocusStyles", () => {
104106
it.each([
105107
`<div data-example="<style id='t3-focus'>"></div>`,
106108
`<div data-example='<style id="t3-focus">'></div>`,
109+
`<my-theme_card data-example="<style id='t3-focus'>"></my-theme_card>`,
110+
`<my-theme.card data-example="<style id='t3-focus'>"></my-theme.card>`,
107111
`<style data-example="<style id='t3-focus'>">body{color:red}</style>`,
108112
`<style data-example="id='t3-focus'">body{color:red}</style>`,
109113
`<style id="T3-FOCUS">body{color:red}</style>`,

‎packages/shared/src/htmlRender.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ const blankNonMarkup = (html: string) => {
395395

396396
/** Refreshes a generated page's focus policy without changing its stored bytes or theme bootstrap. */
397397
export function injectHtmlRenderFocusStyles(html: string): string | undefined {
398-
const tags = /<(\/?)([a-z][a-z0-9:-]*)(?=[\s/>])|<!--|<!|<\?/gi;
398+
const tags = /<(\/?)([a-z][^\t\n\f\r />]*)(?=[\t\n\f\r />])|<!--|<!|<\?/gi;
399399
let themeAt: number | undefined;
400400
let hasFocus = false;
401401
let templateDepth = 0;
@@ -442,7 +442,7 @@ export function injectHtmlRenderFocusStyles(html: string): string | undefined {
442442
!closing &&
443443
/^(?:script|style|textarea|title|xmp|iframe|noembed|noframes|noscript)$/u.test(name ?? "")
444444
) {
445-
const rawEnd = new RegExp(`</${name}(?=[\\s/>])`, "gi");
445+
const rawEnd = new RegExp(`</${name}(?=[\\t\\n\\f\\r />])`, "gi");
446446
rawEnd.lastIndex = tags.lastIndex;
447447
const closed = rawEnd.exec(html);
448448
tags.lastIndex = closed ? closed.index : html.length;

0 commit comments

Comments
 (0)