Skip to content

Commit

Permalink
fix space at beginning of input causing infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dcastil committed Aug 12, 2024
1 parent 14166d3 commit 400b90d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/lib/merge-classlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
const classGroupsInConflict: string[] = []

let result = ''
let index = classList.length - 1

for (let i = classList.length - 1; i >= 0; ) {
while (classList[i] === ' ') {
--i
while (index >= 0) {
while (classList[index] === ' ') {
index -= 1
}
const nextI = classList.lastIndexOf(' ', i)
const originalClassName = classList.slice(nextI === -1 ? 0 : nextI + 1, i + 1)
i = nextI

if (index < 0) {
break
}

const nextIndex = classList.lastIndexOf(' ', index)
const originalClassName = classList.slice(nextIndex + 1, index + 1)

index = nextIndex

const { modifiers, hasImportantModifier, baseClassName, maybePostfixModifierPosition } =
parseClassName(originalClassName)
Expand Down

0 comments on commit 400b90d

Please sign in to comment.