[FIX] blockdom: fix crash when class object key has leading spaces

Previously, having a leading or trailing space caused
HTMLElement.classList.add to be called with an empty string (because we
are splitting on whitespace), which is not allowed and caused a crash.
This commit fixes that by trimming the keys of the class object in the
same way that we already do it for class strings.
This commit is contained in:
Samuel Degueldre
2022-06-22 15:36:36 +02:00
committed by Géry Debongnie
parent 2e03332acd
commit e57e2ee378
3 changed files with 118 additions and 0 deletions
+4
View File
@@ -93,6 +93,10 @@ function toClassObj(expr: string | number | { [c: string]: any }) {
for (let key in expr as any) {
const value = (expr as any)[key];
if (value) {
key = trim.call(key);
if (!key) {
continue;
}
const words = split.call(key, wordRegexp);
for (let word of words) {
result[word] = value;