Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,20 @@ private void refillBuffer() throws IOException {
cdataBuffer.setLength(0);
}
} else {
// Character doesn't match the next position in "]]>"
// First, write any previously buffered partial "]]>" match
if (cdataEndMatchPos > 0) {
cdataBuffer.append(ch);
writeStringToBuffer(cdataBuffer.toString());
cdataBuffer.setLength(0);
cdataEndMatchPos = 0;
}
// Now check if current character could start a new "]]>" match
if (ch == CDATA_END.charAt(0)) {
// Start matching "]]>"
cdataEndMatchPos = 1;
cdataBuffer.append(ch);
} else {
// Inside CDATA, write character as-is (but still validate XML char)
// Just a regular character in CDATA
writeStringToBuffer(String.valueOf(ch));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ void testInvalidXmlEscapeStringWithinCdata() {
item.getDescription().orElse(""));
}

@Test
void testCdataEndingWithTripleRightSquareBrackets() {
var items = new RssReader()
.addFeedFilter(new InvalidXmlCharacterFilter())
.read(fromFile("rss-cdata-ending-triple-right-square-brackets.xml")).collect(Collectors.toList());

assertEquals(20, items.size());
var item = items.get(0);

assertEquals("Sorti le 21 octobre dernier, Painkiller, le FPS action-coop « revisitant » le cultissime et unique Painkiller des années 2000 cher à nos cœurs, n’a pas connu le succès escompté et sa petite fanbase de joueurs commençait à s’inquiéter de ne pas avoir de nouvelles. Fort heureusement, la semaine dernière, le studio Anshar a publié […]", item.getDescription().orElse(""));
}

private InputStream fromFile(String fileName) {
return getClass().getClassLoader().getResourceAsStream(fileName);
}
Expand Down
Loading