Skip to content

Commit 11c749d

Browse files
joehnimichael-o
authored andcommitted
Fix endless loop with invalid PI containing XML (codehaus-plexus#122)
This closes codehaus-plexus#122
1 parent 2c6fe7e commit 11c749d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -3158,6 +3158,10 @@ else if ( !seenInnerTag )
31583158
throw new XmlPullParserException( "processing instruction started on line " + curLine
31593159
+ " and column " + curColumn + " was not closed", this, null );
31603160
}
3161+
else
3162+
{
3163+
seenInnerTag = false;
3164+
}
31613165
}
31623166
else if ( ch == '<' )
31633167
{

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

+31
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,37 @@ public void testProcessingInstructionsContainingXml()
432432
*
433433
* @throws java.lang.Exception if any.
434434
*/
435+
@Test
436+
public void testMalformedProcessingInstructionsContainingXmlNoClosingQuestionMark()
437+
throws Exception
438+
{
439+
StringBuffer sb = new StringBuffer();
440+
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
441+
sb.append( "<project />\n" );
442+
sb.append( "<?pi\n" );
443+
sb.append( " <tag>\n" );
444+
sb.append( " </tag>>\n" );
445+
446+
MXParser parser = new MXParser();
447+
parser.setInput( new StringReader( sb.toString() ) );
448+
449+
try
450+
{
451+
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() );
452+
assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() );
453+
assertEquals( XmlPullParser.START_TAG, parser.nextToken() );
454+
assertEquals( XmlPullParser.END_TAG, parser.nextToken() );
455+
assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() );
456+
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() );
457+
458+
fail( "Should fail since it has invalid PI" );
459+
}
460+
catch ( XmlPullParserException ex )
461+
{
462+
assertTrue( ex.getMessage().contains( "processing instruction started on line 3 and column 1 was not closed" ) );
463+
}
464+
}
465+
435466
@Test
436467
public void testSubsequentProcessingInstructionShort()
437468
throws Exception

0 commit comments

Comments
 (0)