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 @@ -2450,6 +2450,7 @@ private void parseComment() throws XmlPullParserException, IOException {
if (pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = cch;
if (cch2 != 0) {
if (pcEnd >= pc.length) ensurePC(pcEnd);
pc[pcEnd++] = cch2;
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ class MXParserTest {
*
* @throws java.lang.Exception if any.
*/
@Test
void commentSurrogatePairAtBufferBoundary() throws Exception {
MXParser parser = new MXParser();
java.lang.reflect.Field pcField = MXParser.class.getDeclaredField("pc");
pcField.setAccessible(true);
int pcLength = ((char[]) pcField.get(parser)).length;

// The leading CR switches the parser to its parsed-content buffer, which then holds the
// normalised LF plus pcLength - 2 characters; the surrogate pair needs the last two slots.
StringBuilder comment = new StringBuilder("\r");
for (int i = 0; i < pcLength - 2; i++) {
comment.append('a');
}
comment.append("\uD83D\uDE00");

parser.setInput(new StringReader("<root><!--" + comment + "--></root>"));

assertEquals(XmlPullParser.START_TAG, parser.nextToken());
assertEquals(XmlPullParser.COMMENT, parser.nextToken());
assertEquals("\n" + comment.substring(1), parser.getText());
assertEquals(XmlPullParser.END_TAG, parser.nextToken());
}

@Test
void hexadecimalEntities() throws Exception {
MXParser parser = new MXParser();
Expand Down
Loading