File tree Expand file tree Collapse file tree
Sources/Ignite/Publishing
Tests/IgniteTesting/Publishing Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,15 @@ struct FeedGenerator {
1717 self . content = content
1818 }
1919
20+ private func xmlEscape( _ string: String ) -> String {
21+ string
22+ . replacingOccurrences ( of: " & " , with: " & " )
23+ . replacingOccurrences ( of: " < " , with: " < " )
24+ . replacingOccurrences ( of: " > " , with: " > " )
25+ . replacingOccurrences ( of: " \" " , with: " " " )
26+ . replacingOccurrences ( of: " ' " , with: " ' " )
27+ }
28+
2029 func generateFeed( ) -> String {
2130 let contentXML = generateContentXML ( )
2231 var result = generateRSSHeader ( )
@@ -25,7 +34,7 @@ struct FeedGenerator {
2534 result += """
2635 <image> \
2736 <url> \( image. url) </url> \
28- <title> \( site. name) </title> \
37+ <title> \( xmlEscape ( site. name) ) </title> \
2938 <link> \( site. url. absoluteString) </link> \
3039 <width> \( image. width) </width> \
3140 <height> \( image. height) </height> \
Original file line number Diff line number Diff line change @@ -20,6 +20,21 @@ struct FeedGeneratorTests {
2020 TestSite ( timeZone: . init( abbreviation: " EST " ) !)
2121 ]
2222
23+ @Test ( " XML-escapes special characters in titles " )
24+ func xmlEscapesSpecialCharacters( ) async throws {
25+ let site = TestSite ( )
26+ let config = site. feedConfiguration!
27+ var article = Article ( )
28+ article. title = " Donations & Sponsorships "
29+ article. description = " Example Description "
30+
31+ let generator = FeedGenerator ( config: config, site: site, content: [ article] )
32+ let feed = generator. generateFeed ( )
33+
34+ #expect( feed. contains ( " <title>Donations & Sponsorships</title> " ) )
35+ #expect( !feed. contains ( " <title>Donations & Sponsorships</title> " ) )
36+ }
37+
2338 @Test ( " generateFeed() " , arguments: await sites)
2439 func generateFeed( for site: any Site ) async throws {
2540 let config = site. feedConfiguration!
You can’t perform that action at this time.
0 commit comments