@@ -169,11 +169,40 @@ public static function removeAttributes(string $html = ''): string
169
169
170
170
foreach ($ attributes [0 ] as $ attribute ) {
171
171
$ attributeName = stristr ($ attribute , '= ' , true );
172
- if (!in_array ($ attributeName , $ keep )) {
172
+ if (self :: isAttribute ( $ attributeName ) && !in_array ($ attributeName , $ keep )) {
173
173
$ html = str_replace (' ' . $ attribute , '' , $ html );
174
174
}
175
175
}
176
176
177
177
return $ html ;
178
178
}
179
+
180
+ /**
181
+ * @param string $attribute
182
+ * @return bool
183
+ */
184
+ private static function isAttribute (string $ attribute ): bool
185
+ {
186
+ $ globalAttributes = [
187
+ 'autocomplete ' , 'autofocus ' , 'disabled ' , 'list ' , 'name ' , 'readonly ' , 'required ' , 'tabindex ' , 'type ' ,
188
+ 'value ' , 'accesskey ' , 'class ' , 'contenteditable ' , 'contextmenu ' , 'dir ' , 'draggable ' , 'dropzone ' , 'id ' ,
189
+ 'lang ' , 'style ' , 'tabindex ' , 'title ' , 'inputmode ' , 'is ' , 'itemid ' , 'itemprop ' , 'itemref ' , 'itemscope ' ,
190
+ 'itemtype ' , 'lang ' , 'slot ' , 'spellcheck ' , 'translate ' , 'autofocus ' , 'disabled ' , 'form ' , 'multiple ' , 'name ' ,
191
+ 'required ' , 'size ' , 'autocapitalize ' , 'autocomplete ' , 'autofocus ' , 'cols ' , 'disabled ' , 'form ' , 'maxlength ' ,
192
+ 'minlength ' , 'name ' , 'placeholder ' , 'readonly ' , 'required ' , 'rows ' , 'spellcheck ' , 'wrap ' , 'onmouseenter ' ,
193
+ 'onmouseleave ' , 'onafterprint ' , 'onbeforeprint ' , 'onbeforeunload ' , 'onhashchange ' , 'onmessage ' , 'onoffline ' ,
194
+ 'ononline ' , 'onpopstate ' , 'onpagehide ' , 'onpageshow ' , 'onresize ' , 'onunload ' , 'ondevicemotion ' , 'preload ' ,
195
+ 'ondeviceorientation ' , 'onabort ' , 'onblur ' , 'oncanplay ' , 'oncanplaythrough ' , 'onchange ' , 'onclick ' ,
196
+ 'oncontextmenu ' , 'ondblclick ' , 'ondrag ' , 'ondragend ' , 'ondragenter ' , 'ondragleave ' , 'ondragover ' ,
197
+ 'ondragstart ' , 'ondrop ' , 'ondurationchange ' , 'onemptied ' , 'onended ' , 'onerror ' , 'onfocus ' , 'oninput ' ,
198
+ 'oninvalid ' , 'onkeydown ' , 'onkeypress ' , 'onkeyup ' , 'onload ' , 'onloadeddata ' , 'onloadedmetadata ' ,
199
+ 'onloadstart ' , 'onmousedown ' , 'onmousemove ' , 'onmouseout ' , 'onmouseover ' , 'onmouseup ' ,'controls ' ,
200
+ 'onmozfullscreenchange ' , 'onmozfullscreenerror ' , 'onpause ' , 'onplay ' , 'onplaying ' , 'onprogress ' ,
201
+ 'onratechange ' , 'onreset ' , 'onscroll ' , 'onseeked ' , 'onseeking ' , 'onselect ' , 'onshow ' , 'onstalled ' ,
202
+ 'onsubmit ' , 'onsuspend ' , 'ontimeupdate ' , 'onvolumechange ' , 'onwaiting ' , 'oncopy ' , 'oncut ' , 'onpaste ' ,
203
+ 'onbeforescriptexecute ' , 'onafterscriptexecute '
204
+ ];
205
+
206
+ return in_array ($ attribute , $ globalAttributes );
207
+ }
179
208
}
0 commit comments