@@ -85,6 +85,40 @@ static const char * const argname[] = {
8585 /* ARG_FLAG_FLAT_ARRAY */
8686};
8787
88+ /* https://meiert.com/en/blog/boolean-attributes-of-html/ */
89+ const static struct boolean_attribute {
90+ int len ;
91+ char * str ;
92+ }
93+ boolean_attributes [] = {
94+ {15 , "allowfullscreen" },
95+ {19 , "allowpaymentrequest" },
96+ {5 , "async" },
97+ {9 , "autofocus" },
98+ {8 , "autoplay" },
99+ {6 , "checked" },
100+ {8 , "controls" },
101+ {7 , "default" },
102+ {8 , "disabled" },
103+ {14 , "formnovalidate" },
104+ {6 , "hidden" },
105+ {5 , "ismap" },
106+ {9 , "itemscope" },
107+ {4 , "loop" },
108+ {8 , "multiple" },
109+ {5 , "muted" },
110+ {8 , "nomodule" },
111+ {10 , "novalidate" },
112+ {4 , "open" },
113+ {11 , "playsinline" },
114+ {8 , "readonly" },
115+ {8 , "required" },
116+ {8 , "reversed" },
117+ {8 , "selected" },
118+ {9 , "truespeed" },
119+ {0 , 0 }
120+ };
121+
88122#define CASE_SENSITIVE (p_state ) \
89123 ((p_state)->xml_mode || (p_state)->case_sensitive)
90124#define STRICT_NAMES (p_state ) \
@@ -438,8 +472,8 @@ report_event(PSTATE* p_state,
438472 }
439473
440474 for (i = 1 ; i < num_tokens ; i += 2 ) {
441- SV * attrname = newSVpvn ( tokens [i ].beg ,
442- tokens [i ].end - tokens [ i ]. beg );
475+ int attrlen = tokens [i ].end - tokens [ i ]. beg ;
476+ SV * attrname = newSVpvn ( tokens [i ].beg , attrlen );
443477 SV * attrval ;
444478
445479 if (utf8 )
@@ -465,11 +499,33 @@ report_event(PSTATE* p_state,
465499 }
466500 }
467501 else { /* boolean */
468- if (p_state -> bool_attr_val )
469- attrval = newSVsv (p_state -> bool_attr_val );
470- else
471- attrval = newSV (0 );
472- }
502+ int i ;
503+ for ( i = 0 ; boolean_attributes [i ].len ; i ++ ) {
504+ if ( attrlen == boolean_attributes [i ].len ) {
505+ char * attrname_s = tokens [i ].beg ;
506+ char * t = boolean_attributes [i ].str ;
507+ int len = attrlen ;
508+ while (len ) {
509+ if (toLOWER (* attrname_s ) != * t )
510+ break ;
511+ attrname_s ++ ;
512+ t ++ ;
513+ if (!-- len ) {
514+ /* this is a boolean attribute */
515+ if (p_state -> bool_attr_val )
516+ attrval = newSVsv (p_state -> bool_attr_val );
517+ else
518+ attrval = newSVsv (attrname );
519+ }
520+ goto BOOLEAN_ATTR_MATCH_DONE ;
521+ }
522+ }
523+ }
524+ /* no matches were found, so set attr to undef */
525+ attrval = newSV (0 );
526+ BOOLEAN_ATTR_MATCH_DONE :
527+ ;
528+ }
473529
474530 if (!CASE_SENSITIVE (p_state ))
475531 sv_lower (aTHX_ attrname );
0 commit comments