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 89b8ef5

Browse filesBrowse files
joehnimichael-o
authored andcommitted
Fix position on MXParser (#121)
This closes #121
1 parent 407a93c commit 89b8ef5
Copy full SHA for 89b8ef5

File tree

Expand file treeCollapse file tree

2 files changed

+42
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+42
-7
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
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ private void reset()
464464
// System.out.println("reset() called");
465465
location = null;
466466
lineNumber = 1;
467-
columnNumber = 0;
467+
columnNumber = 1;
468468
seenRoot = false;
469469
reachedEnd = false;
470470
eventType = START_DOCUMENT;
@@ -3156,7 +3156,7 @@ else if ( !seenInnerTag )
31563156
{
31573157
// seenPITarget && !seenQ
31583158
throw new XmlPullParserException( "processing instruction started on line " + curLine
3159-
+ " and column " + curColumn + " was not closed", this, null );
3159+
+ " and column " + (curColumn -2) + " was not closed", this, null );
31603160
}
31613161
}
31623162
else if ( ch == '<' )

‎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
+40-5Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,35 @@ public void testValidCharacterReferenceDecimal()
353353
*
354354
* @throws java.lang.Exception if any.
355355
*/
356+
@Test
357+
public void testParserPosition()
358+
throws Exception
359+
{
360+
String input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!-- A --> \n <!-- B --><test>\tnnn</test>\n<!-- C\nC -->";
361+
362+
MXParser parser = new MXParser();
363+
parser.setInput( new StringReader( input ) );
364+
365+
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() );
366+
assertPosition( 1, 39, parser );
367+
assertEquals( XmlPullParser.COMMENT, parser.nextToken() );
368+
assertPosition( 1, 49, parser );
369+
assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() );
370+
assertPosition( 2, 3, parser ); // end when next token starts
371+
assertEquals( XmlPullParser.COMMENT, parser.nextToken() );
372+
assertPosition( 2, 12, parser );
373+
assertEquals( XmlPullParser.START_TAG, parser.nextToken() );
374+
assertPosition( 2, 18, parser );
375+
assertEquals( XmlPullParser.TEXT, parser.nextToken() );
376+
assertPosition( 2, 23, parser ); // end when next token starts
377+
assertEquals( XmlPullParser.END_TAG, parser.nextToken() );
378+
assertPosition( 2, 29, parser );
379+
assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() );
380+
assertPosition( 3, 2, parser ); // end when next token starts
381+
assertEquals( XmlPullParser.COMMENT, parser.nextToken() );
382+
assertPosition( 4, 6, parser );
383+
}
384+
356385
@Test
357386
public void testProcessingInstruction()
358387
throws Exception
@@ -624,7 +653,7 @@ public void testMalformedProcessingInstructionNoClosingQuestionMark()
624653
}
625654
catch ( XmlPullParserException ex )
626655
{
627-
assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 2 was not closed" ) );
656+
assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 1 was not closed" ) );
628657
}
629658
}
630659

@@ -657,7 +686,7 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark()
657686
}
658687
catch ( XmlPullParserException ex )
659688
{
660-
assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 13 was not closed" ) );
689+
assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 12 was not closed" ) );
661690
}
662691
}
663692

@@ -900,6 +929,12 @@ public void testEncodingISO_8859_1_setInputStream()
900929
}
901930
}
902931

932+
private static void assertPosition( int row, int col, MXParser parser )
933+
{
934+
assertEquals( "Current line", row, parser.getLineNumber() );
935+
assertEquals( "Current column", col, parser.getColumnNumber() );
936+
}
937+
903938
/**
904939
* Issue 163: https://github.com/codehaus-plexus/plexus-utils/issues/163
905940
*
@@ -958,7 +993,7 @@ public void testCustomEntityNotFoundInText()
958993
}
959994
catch ( XmlPullParserException e )
960995
{
961-
assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_TAG seen <root>&otherentity;... @1:19)" ) );
996+
assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_TAG seen <root>&otherentity;... @1:20)" ) );
962997
assertEquals( XmlPullParser.START_TAG, parser.getEventType() ); // not an ENTITY_REF
963998
assertEquals( "otherentity", parser.getText() );
964999
}
@@ -1025,7 +1060,7 @@ public void testCustomEntityNotFoundInAttr()
10251060
}
10261061
catch ( XmlPullParserException e )
10271062
{
1028-
assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen <root name=\"&otherentity;... @1:25)" ) );
1063+
assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen <root name=\"&otherentity;... @1:26)" ) );
10291064
assertEquals( XmlPullParser.START_DOCUMENT, parser.getEventType() ); // not an ENTITY_REF
10301065
assertNull( parser.getText() );
10311066
}
@@ -1060,7 +1095,7 @@ public void testCustomEntityNotFoundInAttrTokenize() throws Exception
10601095
}
10611096
catch ( XmlPullParserException e )
10621097
{
1063-
assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen <root name=\"&otherentity;... @1:25)" ) );
1098+
assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen <root name=\"&otherentity;... @1:26)" ) );
10641099
assertEquals( XmlPullParser.START_DOCUMENT, parser.getEventType() ); // not an ENTITY_REF
10651100
assertNull( parser.getText() );
10661101
}

0 commit comments

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