Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0d97c8b

Browse filesBrowse files
joehnimichael-o
authored andcommitted
Fix endless loop caused by aborted subsequent PI or comment (#124)
This closes #124
1 parent 11c749d commit 0d97c8b
Copy full SHA for 0d97c8b

File tree

Expand file treeCollapse file tree

2 files changed

+53
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+53
-1
lines changed

‎src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java

Copy file name to clipboardExpand all lines: src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3964,7 +3964,7 @@ private char more()
39643964
fillBuf();
39653965
// this return value should be ignored as it is used in epilog parsing ...
39663966
if ( reachedEnd )
3967-
return (char) -1;
3967+
throw new EOFException( "no more data available" + getPositionDescription() );
39683968
}
39693969
final char ch = buf[pos++];
39703970
// line/columnNumber

‎src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,58 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark()
726726
*
727727
* @throws java.lang.Exception if any.
728728
*/
729+
@Test
730+
public void testSubsequentAbortedProcessingInstruction()
731+
throws Exception
732+
{
733+
MXParser parser = new MXParser();
734+
StringBuilder sb = new StringBuilder();
735+
sb.append( "<project />" );
736+
sb.append( "<?aborted" );
737+
738+
parser.setInput( new StringReader( sb.toString() ) );
739+
740+
try
741+
{
742+
assertEquals( XmlPullParser.START_TAG, parser.next() );
743+
assertEquals( XmlPullParser.END_TAG, parser.next() );
744+
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.next() );
745+
746+
fail( "Should fail since it has aborted PI" );
747+
}
748+
catch ( XmlPullParserException ex )
749+
{
750+
assertTrue( ex.getMessage().contains( "@1:21" ) );
751+
assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 12 was not closed" ) );
752+
}
753+
}
754+
755+
@Test
756+
public void testSubsequentAbortedComment()
757+
throws Exception
758+
{
759+
MXParser parser = new MXParser();
760+
StringBuilder sb = new StringBuilder();
761+
sb.append( "<project />" );
762+
sb.append( "<!-- aborted" );
763+
764+
parser.setInput( new StringReader( sb.toString() ) );
765+
766+
try
767+
{
768+
assertEquals( XmlPullParser.START_TAG, parser.next() );
769+
assertEquals( XmlPullParser.END_TAG, parser.next() );
770+
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.next() );
771+
772+
fail( "Should fail since it has aborted comment" );
773+
}
774+
catch ( XmlPullParserException ex )
775+
{
776+
assertTrue( ex.getMessage().contains( "@1:24" ) );
777+
assertTrue( ex.getMessage().contains( "comment started on line 1 and column 12 was not closed" ) );
778+
}
779+
}
780+
729781
@Test
730782
public void testMalformedXMLRootElement()
731783
throws Exception

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.