@@ -77,16 +77,19 @@ export class HtmlRenderViewportHeightError extends Schema.TaggedError<HtmlRender
7777}
7878
7979// Only stylesheets and style attributes are checked, so page text that mentions
80- // a unit passes. An unclosed tag or quote runs to the end of the page, which
81- // keeps both patterns linear on hostile input.
80+ // a unit passes; comments match first so their contents are skipped. Scripts
81+ // are still checked, since markup they insert applies. An unclosed comment,
82+ // tag, or quote runs to the end of the page, which keeps both patterns linear
83+ // on hostile input.
8284const CSS_SOURCE =
83- / < s t y l e \b [ ^ > ] * (?: > | $ ) ( [ \s \S ] * ?) (?: < \/ s t y l e \s * > | $ ) | \s s t y l e \s * = \s * (?: " ( [ ^ " ] * ) (?: " | $ ) | ' ( [ ^ ' ] * ) (?: ' | $ ) ) / gi;
85+ / < ! - - [ \s \S ] * ? (?: - - > | $ ) | < s t y l e \b [ ^ > ] * (?: > | $ ) ( [ \s \S ] * ?) (?: < \/ s t y l e \s * > | $ ) | \s s t y l e \s * = \s * (?: " ( [ ^ " ] * ) (?: " | $ ) | ' ( [ ^ ' ] * ) (?: ' | $ ) | ( [ ^ \s > ] + ) ) / gi;
8486// The lookbehind skips base64 runs, such as an inlined image that happens to contain "1vh".
8587const VIEWPORT_HEIGHT_UNIT = / (?< ! [ \w . + / ] ) (?: \d + (?: \. \d + ) ? | \. \d + ) [ s l d ] ? v h (? ! [ \w - ] ) / i;
8688
8789const rejectViewportHeight = ( html : string ) => {
88- for ( const [ , sheet , doubleQuoted , singleQuoted ] of html . matchAll ( CSS_SOURCE ) ) {
89- const found = VIEWPORT_HEIGHT_UNIT . exec ( sheet ?? doubleQuoted ?? singleQuoted ?? "" ) ?. [ 0 ] ;
90+ for ( const [ , sheet , doubleQuoted , singleQuoted , unquoted ] of html . matchAll ( CSS_SOURCE ) ) {
91+ const css = sheet ?? doubleQuoted ?? singleQuoted ?? unquoted ?? "" ;
92+ const found = VIEWPORT_HEIGHT_UNIT . exec ( css ) ?. [ 0 ] ;
9093 if ( found !== undefined ) return Effect . fail ( new HtmlRenderViewportHeightError ( { found } ) ) ;
9194 }
9295 return Effect . void ;
0 commit comments