Skip to content

Commit

Permalink
[LiveComponent] Tokenize classes on all allowed whitespaces
Browse files Browse the repository at this point in the history
The class attribute can be tokenized by any white space as defined by
the HTML spec. A class string containing new lines was not correctly
cleaned / trimmed, resulting in incorrectly detected class changes and a
browser error if empty classes or classes with newlines were applied.

Fixes symfony#1819
  • Loading branch information
aleho committed May 13, 2024
1 parent 796dd58 commit dd04858
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/LiveComponent/assets/src/Rendering/ExternalMutationTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,8 @@ export default class {
private handleClassAttributeMutation(mutation: MutationRecord, elementChanges: ElementChanges) {
const element = mutation.target as Element;

const previousValue = mutation.oldValue;
const previousValues = previousValue ? previousValue.split(' ') : [];
previousValues.forEach((value, index) => {
const trimmedValue = value.trim();
if (trimmedValue !== '') {
previousValues[index] = trimmedValue;
} else {
previousValues.splice(index, 1);
}
});
const previousValue = mutation.oldValue || '';
const previousValues = previousValue.match(/(\S+)/gu) || [];

const newValues: string[] = [].slice.call(element.classList);
const addedValues = newValues.filter((value) => !previousValues.includes(value));
Expand Down

0 comments on commit dd04858

Please sign in to comment.