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 bb346ad

Browse filesBrowse files
authored
Fixes #163: Regression: encoding error when parsing a ISO-8859-1 xml (#164)
- Fixed code. - Added tests.
1 parent 5e6d78e commit bb346ad
Copy full SHA for bb346ad

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+1568
-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
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.io.UnsupportedEncodingException;
1717

1818
import org.codehaus.plexus.util.ReaderFactory;
19+
import org.codehaus.plexus.util.xml.XmlReader;
1920

2021
//import java.util.Hashtable;
2122

@@ -663,7 +664,12 @@ public void setInput( Reader in )
663664
reset();
664665
reader = in;
665666

666-
if ( reader instanceof InputStreamReader )
667+
if ( reader instanceof XmlReader ) {
668+
// encoding already detected
669+
XmlReader xsr = (XmlReader) reader;
670+
fileEncoding = xsr.getEncoding();
671+
}
672+
else if ( reader instanceof InputStreamReader )
667673
{
668674
InputStreamReader isr = (InputStreamReader) reader;
669675
if ( isr.getEncoding() != null )

‎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
+58Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@
2121
import static org.junit.Assert.fail;
2222

2323
import java.io.EOFException;
24+
import java.io.File;
2425
import java.io.IOException;
26+
import java.io.InputStream;
27+
import java.io.Reader;
2528
import java.io.StringReader;
29+
import java.nio.file.Files;
30+
import java.nio.file.Paths;
2631

32+
import org.codehaus.plexus.util.ReaderFactory;
2733
import org.junit.Test;
2834

2935
/**
@@ -840,4 +846,56 @@ public void testXMLDeclVersionEncodingStandaloneNoSpace()
840846
}
841847
}
842848

849+
/**
850+
* Issue 163: https://github.com/codehaus-plexus/plexus-utils/issues/163
851+
*
852+
* @throws IOException if IO error.
853+
*
854+
* @since 3.4.1
855+
*/
856+
@Test
857+
public void testEncodingISO_8859_1setInputReader()
858+
throws IOException
859+
{
860+
try ( Reader reader =
861+
ReaderFactory.newXmlReader( new File( "src/test/resources/xml", "test-encoding-ISO-8859-1.xml" ) ) )
862+
{
863+
MXParser parser = new MXParser();
864+
parser.setInput( reader );
865+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
866+
;
867+
assertTrue( true );
868+
}
869+
catch ( XmlPullParserException e )
870+
{
871+
fail( "should not raise exception: " + e );
872+
}
873+
}
874+
875+
/**
876+
* Issue 163: https://github.com/codehaus-plexus/plexus-utils/issues/163
877+
*
878+
* @throws IOException if IO error.
879+
*
880+
* @since 3.4.1
881+
*/
882+
@Test
883+
public void testEncodingISO_8859_1_setInputStream()
884+
throws IOException
885+
{
886+
try ( InputStream input =
887+
Files.newInputStream( Paths.get( "src/test/resources/xml", "test-encoding-ISO-8859-1.xml" ) ) )
888+
{
889+
MXParser parser = new MXParser();
890+
parser.setInput( input, null );
891+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
892+
;
893+
assertTrue( true );
894+
}
895+
catch ( XmlPullParserException e )
896+
{
897+
fail( "should not raise exception: " + e );
898+
}
899+
}
900+
843901
}

0 commit comments

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