@@ -133,6 +133,7 @@ private function resetState(): void
133133 $ this ->selfClosing = false ;
134134 $ this ->attributeValue = '' ;
135135 $ this ->attributeName = '' ;
136+ $ this ->originalAttributeName = '' ;
136137 $ this ->nameBuffer = '' ;
137138 $ this ->isClosing = false ;
138139 }
@@ -545,7 +546,8 @@ private function renderTagName(Document $document): Document
545546 private function renderBeforeAttributeName (Document $ document ): Document
546547 {
547548 $ oops = function (string $ c , Closure $ next ) use ($ document ) {
548- $ this ->attributeName = $ c ;
549+ $ this ->attributeName = strtolower ($ c );
550+ $ this ->originalAttributeName = $ c ;
549551 $ this ->attributeValue = '' ;
550552 return $ next ($ document );
551553 };
@@ -560,6 +562,7 @@ private function renderBeforeAttributeName(Document $document): Document
560562 return $ result ;
561563 }
562564 $ this ->attributeName = '' ;
565+ $ this ->originalAttributeName = '' ;
563566 $ this ->attributeValue = '' ;
564567 return $ document ->reconsume ($ this ->renderAttributeName (...));
565568 }
@@ -1130,6 +1133,8 @@ private function renderBogusDocType(Document $document): Document
11301133 return $ this ->renderBogusDocType ($ document );
11311134 }
11321135
1136+ private string $ originalAttributeName = '' ;
1137+
11331138 private function renderAttributeName (Document $ document ): Document
11341139 {
11351140 //$selectionStart = $document->mark();
@@ -1143,6 +1148,7 @@ private function renderAttributeName(Document $document): Document
11431148 return $ result ;
11441149 }
11451150 $ this ->attributeName .= strtolower ($ char );
1151+ $ this ->originalAttributeName .= $ char ;
11461152 goto renderAttributeName;
11471153 }
11481154
@@ -1153,7 +1159,7 @@ private function renderBeforeAttributeValue(Document $document): Document
11531159 '" ' => $ this ->renderAttributeValueDoubleQuoted ($ document ),
11541160 "' " => $ this ->renderAttributeValueSingleQuoted ($ document ),
11551161 '> ' => (function () use ($ document ) {
1156- $ this ->setAttribute ($ this ->attributeName );
1162+ $ this ->setAttribute ($ this ->originalAttributeName );
11571163 return $ document ;
11581164 })(),
11591165 default => $ this ->renderAttributeValueUnquoted ($ document ),
@@ -1207,7 +1213,7 @@ private function processAttributes(Document $document): Document
12071213 $ value = $ this ->escaper ->escapeHtmlAttr ($ originalValue );
12081214 // escaper doesn't escape single quotes, so we do that here.
12091215 $ value = str_replace ("' " , '' ' , $ value );
1210- $ this ->setAttribute ($ this ->attributeName , $ originalValue );
1216+ $ this ->setAttribute ($ this ->originalAttributeName , $ originalValue );
12111217 if ($ value !== $ this ->attributeValue ) {
12121218 // we need to update the rendered html too...
12131219 $ here = $ document ->mark ();
@@ -1263,8 +1269,8 @@ private function renderAttributeValueUnquoted(Document $document): Document
12631269
12641270 private function renderAfterAttributeName (Document $ document ): Document
12651271 {
1266- if (!empty ($ this ->attributeName ) && !array_key_exists ($ this ->attributeName , $ this ->attributes )) {
1267- $ this ->setAttribute ($ this ->attributeName );
1272+ if (!empty ($ this ->attributeName ) && !array_key_exists ($ this ->originalAttributeName , $ this ->attributes )) {
1273+ $ this ->setAttribute ($ this ->originalAttributeName );
12681274 }
12691275 $ result = match ($ document ->consume ()) {
12701276 "\t" , "\n" , "\f" , " " => $ this ->renderAfterAttributeName ($ document ),
@@ -1278,6 +1284,7 @@ private function renderAfterAttributeName(Document $document): Document
12781284 }
12791285 $ this ->attributeName = '' ;
12801286 $ this ->attributeValue = '' ;
1287+ $ this ->originalAttributeName = '' ;
12811288 return $ document ->reconsume ($ this ->renderAttributeName (...));
12821289 }
12831290
0 commit comments