4
4
5
5
import java .time .Instant ;
6
6
import java .util .Arrays ;
7
+ import java .util .Collections ;
7
8
import org .junit .jupiter .api .Test ;
8
9
9
10
class RSS2Test {
@@ -130,4 +131,58 @@ void extractRssTagsTest() {
130
131
""" .formatted (lastBuildDate );
131
132
assertThat (rssXml ).isEqualToIgnoringWhitespace (expected );
132
133
}
134
+
135
+ @ Test
136
+ void invalidCharTest () {
137
+ var rss = RSS2 .builder ()
138
+ .title ("title" )
139
+ .description ("description" )
140
+ .link ("link" )
141
+ .items (Collections .singletonList (
142
+ RSS2 .Item .builder ()
143
+ .title ("title1" )
144
+ .description ("""
145
+ <p>并且会保留处理后的图片以供后面的访问。</p>
146
+ """ )
147
+ .link ("link1" )
148
+ .pubDate (Instant .EPOCH )
149
+ .guid ("guid1" )
150
+ .build ()
151
+ ))
152
+ .build ();
153
+ var instant = Instant .now ();
154
+ var rssXml = new RssXmlBuilder ()
155
+ .withRss2 (rss )
156
+ .withGenerator ("Halo" )
157
+ .withLastBuildDate (instant )
158
+ .toXmlString ();
159
+
160
+ var lastBuildDate = RssXmlBuilder .instantToString (instant );
161
+ // language=xml
162
+ var expected = """
163
+ <?xml version="1.0" encoding="UTF-8"?>
164
+ <rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
165
+ <channel>
166
+ <title>title</title>
167
+ <link>link</link>
168
+ <description>description</description>
169
+ <generator>Halo</generator>
170
+ <language>zh-cn</language>
171
+ <lastBuildDate>%s</lastBuildDate>
172
+ <item>
173
+ <title>
174
+ <![CDATA[title1]]>
175
+ </title>
176
+ <link>link1</link>
177
+ <description>
178
+ <![CDATA[<p>并且会保留处理后的图片以供后面的访问。</p>]]>
179
+ </description>
180
+ <guid isPermaLink="false">guid1</guid>
181
+ <pubDate>Thu, 1 Jan 1970 00:00:00 GMT</pubDate>
182
+ </item>
183
+ </channel>
184
+ </rss>
185
+ """ .formatted (lastBuildDate );
186
+ assertThat (rssXml ).isEqualToIgnoringWhitespace (expected );
187
+ }
133
188
}
0 commit comments