Skip to content

Commit

Permalink
Fix for UTF8 character counting in class names
Browse files Browse the repository at this point in the history
  • Loading branch information
amyworrall authored and aehlke committed Feb 28, 2025
1 parent 18ad8b8 commit 9da071d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Element.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ open class Element: Node {
var inClass: Bool = false
var start: Int = 0
for i in 0..<len {
if (classAttr.charAt(i).isWhitespace) {
if (classAttr.utf8CharAt(i).isWhitespace) {
if (inClass) {
// white space ends a class name, compare it with the requested one, ignore case
if (i - start == wantLen && classAttr.regionMatches(ignoreCase: true, selfOffset: start,
Expand Down
4 changes: 4 additions & 0 deletions Sources/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ extension String {
return self[i] as Character
}

func utf8CharAt(_ i: Int) -> UTF8Char {
return self.utf8Array[i]
}

func substring(_ beginIndex: Int) -> String {
return String.split(self, beginIndex, self.count-beginIndex)
}
Expand Down

0 comments on commit 9da071d

Please sign in to comment.