@@ -125,11 +125,40 @@ public static function removeAttributes(string $html = ''): string
125
125
126
126
foreach ($ attributes [0 ] as $ attribute ) {
127
127
$ attributeName = stristr ($ attribute , '= ' , true );
128
- if (!in_array ($ attributeName , $ keep )) {
128
+ if (self :: isAttribute ( $ attributeName ) && !in_array ($ attributeName , $ keep )) {
129
129
$ html = str_replace (' ' . $ attribute , '' , $ html );
130
130
}
131
131
}
132
132
133
133
return $ html ;
134
134
}
135
+
136
+ /**
137
+ * @param string $attribute
138
+ * @return bool
139
+ */
140
+ private static function isAttribute (string $ attribute ): bool
141
+ {
142
+ $ globalAttributes = [
143
+ 'autocomplete ' , 'autofocus ' , 'disabled ' , 'list ' , 'name ' , 'readonly ' , 'required ' , 'tabindex ' , 'type ' ,
144
+ 'value ' , 'accesskey ' , 'class ' , 'contenteditable ' , 'contextmenu ' , 'dir ' , 'draggable ' , 'dropzone ' , 'id ' ,
145
+ 'lang ' , 'style ' , 'tabindex ' , 'title ' , 'inputmode ' , 'is ' , 'itemid ' , 'itemprop ' , 'itemref ' , 'itemscope ' ,
146
+ 'itemtype ' , 'lang ' , 'slot ' , 'spellcheck ' , 'translate ' , 'autofocus ' , 'disabled ' , 'form ' , 'multiple ' , 'name ' ,
147
+ 'required ' , 'size ' , 'autocapitalize ' , 'autocomplete ' , 'autofocus ' , 'cols ' , 'disabled ' , 'form ' , 'maxlength ' ,
148
+ 'minlength ' , 'name ' , 'placeholder ' , 'readonly ' , 'required ' , 'rows ' , 'spellcheck ' , 'wrap ' , 'onmouseenter ' ,
149
+ 'onmouseleave ' , 'onafterprint ' , 'onbeforeprint ' , 'onbeforeunload ' , 'onhashchange ' , 'onmessage ' , 'onoffline ' ,
150
+ 'ononline ' , 'onpopstate ' , 'onpagehide ' , 'onpageshow ' , 'onresize ' , 'onunload ' , 'ondevicemotion ' ,
151
+ 'ondeviceorientation ' , 'onabort ' , 'onblur ' , 'oncanplay ' , 'oncanplaythrough ' , 'onchange ' , 'onclick ' ,
152
+ 'oncontextmenu ' , 'ondblclick ' , 'ondrag ' , 'ondragend ' , 'ondragenter ' , 'ondragleave ' , 'ondragover ' ,
153
+ 'ondragstart ' , 'ondrop ' , 'ondurationchange ' , 'onemptied ' , 'onended ' , 'onerror ' , 'onfocus ' , 'oninput ' ,
154
+ 'oninvalid ' , 'onkeydown ' , 'onkeypress ' , 'onkeyup ' , 'onload ' , 'onloadeddata ' , 'onloadedmetadata ' ,
155
+ 'onloadstart ' , 'onmousedown ' , 'onmousemove ' , 'onmouseout ' , 'onmouseover ' , 'onmouseup ' ,
156
+ 'onmozfullscreenchange ' , 'onmozfullscreenerror ' , 'onpause ' , 'onplay ' , 'onplaying ' , 'onprogress ' ,
157
+ 'onratechange ' , 'onreset ' , 'onscroll ' , 'onseeked ' , 'onseeking ' , 'onselect ' , 'onshow ' , 'onstalled ' ,
158
+ 'onsubmit ' , 'onsuspend ' , 'ontimeupdate ' , 'onvolumechange ' , 'onwaiting ' , 'oncopy ' , 'oncut ' , 'onpaste ' ,
159
+ 'onbeforescriptexecute ' , 'onafterscriptexecute '
160
+ ];
161
+
162
+ return in_array ($ attribute , $ globalAttributes );
163
+ }
135
164
}
0 commit comments