File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,22 @@ describe("injectHtmlRenderBootstrap", () => {
2121 expect ( injected ) . toContain ( 'name="viewport"' ) ;
2222 } ) ;
2323
24+ it . each ( [
25+ "<html><head data-condition='x > 0'>" ,
26+ '<html><head data-condition="x > 0" data-label=\'it "works"\'>' ,
27+ "<html data-condition='x > 0'>" ,
28+ '<html data-condition="x > 0" data-label="it \'works\'">' ,
29+ ] ) ( "keeps the bootstrap after the complete opening tag: %s" , ( opening ) => {
30+ const prefix = `<!doctype html>${ opening } ` ;
31+ const head = opening . startsWith ( "<html><head" ) ? "" : "<head>" ;
32+ const content = `${ head ? "" : "<title>Report</title></head>" } <body><p>Report</p></body></html>` ;
33+ const injected = injectHtmlRenderBootstrap ( prefix + content ) ;
34+ expect ( injected . startsWith ( `${ prefix } ${ head } <meta charset="utf-8">` ) ) . toBe ( true ) ;
35+ expect ( injected . indexOf ( '<style id="t3-theme">' ) ) . toBeGreaterThan ( prefix . length ) ;
36+ expect ( injected ) . toContain ( "<script>" ) ;
37+ expect ( injected . endsWith ( content ) ) . toBe ( true ) ;
38+ } ) ;
39+
2440 it ( "wraps fragments without a head and keeps existing meta tags" , ( ) => {
2541 const fragment =
2642 '<meta charset="utf-8"><meta name="viewport" content="width=device-width"><p>hi</p>' ;
Original file line number Diff line number Diff line change @@ -415,12 +415,12 @@ const blankNonMarkup = (html: string) => {
415415export function injectHtmlRenderBootstrap ( html : string ) : string {
416416 const scan = blankNonMarkup ( html ) ;
417417 const markup = bootstrapMarkup ( scan ) ;
418- const headOpen = / < h e a d (?: \s [ ^ > ] * ) ? > / i. exec ( scan ) ;
418+ const headOpen = / < h e a d (?: \s (?: [ ^ " ' > ] | " [ ^ " ] * " | ' [ ^ ' ] * ' ) * ) ? > / i. exec ( scan ) ;
419419 if ( headOpen ) {
420420 const at = headOpen . index + headOpen [ 0 ] . length ;
421421 return html . slice ( 0 , at ) + markup + html . slice ( at ) ;
422422 }
423- const htmlOpen = / < h t m l (?: \s [ ^ > ] * ) ? > / i. exec ( scan ) ;
423+ const htmlOpen = / < h t m l (?: \s (?: [ ^ " ' > ] | " [ ^ " ] * " | ' [ ^ ' ] * ' ) * ) ? > / i. exec ( scan ) ;
424424 if ( htmlOpen ) {
425425 const at = htmlOpen . index + htmlOpen [ 0 ] . length ;
426426 return `${ html . slice ( 0 , at ) } <head>${ markup } </head>${ html . slice ( at ) } ` ;
You can’t perform that action at this time.
0 commit comments