@@ -7493,6 +7493,49 @@ describe("SourceProcessor — attribute rewrites as options", () => {
74937493 ) . toContain ( "<input checked>" ) ;
74947494 } ) ;
74957495
7496+ it ( "collapses across the elements each boolean attribute belongs to" , ( ) => {
7497+ for ( const [ element , name ] of [
7498+ [ "input" , "checked" ] ,
7499+ [ "input" , "disabled" ] ,
7500+ [ "script" , "async" ] ,
7501+ [ "script" , "defer" ] ,
7502+ [ "option" , "selected" ] ,
7503+ [ "select" , "multiple" ] ,
7504+ [ "details" , "open" ] ,
7505+ [ "ol" , "reversed" ] ,
7506+ [ "iframe" , "allowfullscreen" ] ,
7507+ [ "video" , "muted" ] ,
7508+ [ "form" , "novalidate" ]
7509+ ] ) {
7510+ expect ( minify ( `<${ element } ${ name } ="${ name } "></${ element } >` ) ) . toContain (
7511+ `<${ element } ${ name } >`
7512+ ) ;
7513+ }
7514+ } ) ;
7515+
7516+ it ( "leaves an attribute that is not boolean on that element" , ( ) => {
7517+ // `hidden` is enumerated in the living standard (`until-found`), so it is
7518+ // not one of these either.
7519+ for ( const [ element , name ] of [
7520+ [ "p" , "checked" ] ,
7521+ [ "div" , "open" ] ,
7522+ [ "span" , "selected" ] ,
7523+ [ "p" , "hidden" ]
7524+ ] ) {
7525+ expect ( minify ( `<${ element } ${ name } ="${ name } ">x</${ element } >` ) ) . toContain (
7526+ `${ name } =${ name } `
7527+ ) ;
7528+ }
7529+ } ) ;
7530+
7531+ it ( "keeps the quotes a value cannot go without" , ( ) => {
7532+ for ( const value of [ "a b" , "a=b" , "a<b" , "a>b" , "a`b" , "a'b" ] ) {
7533+ expect ( minify ( `<p id="${ value } ">x</p>` ) ) . toContain ( `id="${ value } "` ) ;
7534+ }
7535+ expect ( minify ( '<p id="a/b">x</p>' ) ) . toContain ( "id=a/b" ) ;
7536+ expect ( minify ( '<p id="a"b">x</p>' ) ) . toContain ( "id='a\"b'" ) ;
7537+ } ) ;
7538+
74967539 it ( "collapses only where the attribute is a boolean one" , ( ) => {
74977540 expect (
74987541 minify ( '<p contenteditable="contenteditable">x</p>' , {
@@ -7511,6 +7554,36 @@ describe("SourceProcessor — attribute rewrites as options", () => {
75117554 expect ( off ) . toContain ( 'srcset="a.png 1x"' ) ;
75127555 } ) ;
75137556
7557+ it ( "reaches every family the rewrite covers, not only the obvious ones" , ( ) => {
7558+ /** @type {[string, string, string][] } */
7559+ const families = [
7560+ [ '<p dir="RTL">x</p>' , "dir=rtl" , "dir=RTL" ] ,
7561+ [
7562+ '<img srcset="a.png 1x" alt=a>' ,
7563+ 'srcset="a.png 1x"' ,
7564+ 'srcset="a.png 1x"'
7565+ ] ,
7566+ [ '<p class=" b a ">x</p>' , 'class="b a"' , 'class=" b a "' ] ,
7567+ [
7568+ '<meta name=viewport content="width=device-width, initial-scale=1">' ,
7569+ 'content="width=device-width,initial-scale=1"' ,
7570+ 'content="width=device-width, initial-scale=1"'
7571+ ] ,
7572+ [
7573+ '<a ping=" a.php , b.php ">x</a>' ,
7574+ 'ping="a.php , b.php"' ,
7575+ 'ping=" a.php , b.php "'
7576+ ] ,
7577+ [ '<a href=" /a ">x</a>' , "href=/a" , 'href=" /a "' ] ,
7578+ [ '<ol start=" 007 "><li>x</ol>' , "start=7" , 'start=" 007 "' ] ,
7579+ [ '<img width=" 100 " src=a alt=a>' , "width=100" , 'width=" 100 "' ]
7580+ ] ;
7581+ for ( const [ body , on , off ] of families ) {
7582+ expect ( minify ( body ) ) . toContain ( on ) ;
7583+ expect ( minify ( body , { normalizeAttributeValues : false } ) ) . toContain ( off ) ;
7584+ }
7585+ } ) ;
7586+
75147587 it ( "leaves the style attribute to its own option" , ( ) => {
75157588 const body = '<p class=" b a " style="color: #ff0000 ;">x</p>' ;
75167589 expect ( minify ( body , { normalizeAttributeValues : false } ) ) . toContain (
0 commit comments