Skip to content

Commit

Permalink
AaaLD - alternative location for removing html from section headers
Browse files Browse the repository at this point in the history
  • Loading branch information
tonisevener committed Nov 20, 2020
1 parent 4016b8a commit fff01d3
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public extension ArticleAsLivingDocViewModel {
userGroups = newTalkPageTopic.userGroups

if let talkPageSection = newTalkPageTopic.section {
self.buttonsToDisplay = .viewDiscussion(sectionName: Self.sectionTitleWithWikitextStripped(originalTitle: talkPageSection))
self.buttonsToDisplay = .viewDiscussion(sectionName: Self.sectionTitleWithWikitextAndHtmlStripped(originalTitle: talkPageSection))
} else {
self.buttonsToDisplay = .viewDiscussion(sectionName: nil)
}
Expand Down Expand Up @@ -910,14 +910,15 @@ public extension ArticleAsLivingDocViewModel.Event.Large {
}

//strip == signs from all section titles
let finalSet = set.map { Self.sectionTitleWithWikitextStripped(originalTitle: $0) }
let finalSet = set.map { Self.sectionTitleWithWikitextAndHtmlStripped(originalTitle: $0) }

return Set(finalSet)
}

//remove one or more equal signs and zero or more spaces on either side of the title text
private static func sectionTitleWithWikitextStripped(originalTitle: String) -> String {
var loopTitle = originalTitle
//also removing html for display and potential javascript injection issues - https://phabricator.wikimedia.org/T268201
private static func sectionTitleWithWikitextAndHtmlStripped(originalTitle: String) -> String {
var loopTitle = originalTitle.removingHTML

let regex = "^=+\\s*|\\s*=+$"
var maybeMatch = loopTitle.range(of: regex, options: .regularExpression)
Expand Down Expand Up @@ -945,7 +946,7 @@ public extension ArticleAsLivingDocViewModel.Event.Large {
localizedString = String.localizedStringWithFormat(CommonStrings.manySectionsDescription, sections.count)
}

return " " + localizedString.removingHTML
return " " + localizedString
}

private func localizedSectionHtmlSnippet(sectionsSet: Set<String>) -> String? {
Expand Down

0 comments on commit fff01d3

Please sign in to comment.