Skip to content

Commit

Permalink
Merge pull request #4910 from wikimedia/hmtl-bugs
Browse files Browse the repository at this point in the history
Update HtmlUtils to handle apostrophes and ampersands regression bugs
  • Loading branch information
tonisevener authored Aug 1, 2024
2 parents 8dda5f1 + 276a415 commit 6ec97db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions Components/Sources/Components/Utility/HTMLUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,15 @@ public struct HtmlUtils {
}
}


public static func stringFromHTML(_ string: String) throws -> String {
let regex = try htmlTagRegex()
let cleanString = regex.stringByReplacingMatches(in: string, options: [], range: string.fullNSRange, withTemplate: "")
return cleanString
let entityReplaceData = try entityReplaceData(html: cleanString)
let mutableCleanString = NSMutableString(string: cleanString)
for data in entityReplaceData {
mutableCleanString.replaceCharacters(in: data.range, with: data.replaceText)
}
return mutableCleanString as String
}

// MARK: - Shared - Private
Expand Down Expand Up @@ -644,7 +648,7 @@ public struct HtmlUtils {
replaceText = ">"
case "<":
replaceText = "<"
case "&apos;":
case "&apos;", "&#039;":
replaceText = "'"
case "&quot;":
replaceText = "\""
Expand Down
6 changes: 3 additions & 3 deletions Widgets/Widgets/FeaturedArticleWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ struct FeaturedArticleEntry: TimelineEntry {
return content?.languageCode
}

var title: String {
return (content?.displayTitle as NSString?)?.wmf_stringByRemovingHTML() ?? ""
}
var title: String {
return content?.displayTitle.removingHTML ?? ""
}

var description: String {
return content?.description ?? ""
Expand Down

0 comments on commit 6ec97db

Please sign in to comment.