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 a16c27b

Browse filesBrowse files
authored
Fix MXParser do not fail when the leading white space is missing in the (#135)
EncodingDecl in the XMLDecl (file not-wf/P80/ibm80n01.xml) (#134)
1 parent b5a006b commit a16c27b
Copy full SHA for a16c27b

File tree

Expand file treeCollapse file tree

9 files changed

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

9 files changed

+251
-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
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,9 +3274,21 @@ private void parseXmlDeclWithVersion( int versionStart, int versionEnd )
32743274

32753275
// [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
32763276
char ch = more();
3277+
char prevCh = ch;
32773278
ch = skipS( ch );
3279+
3280+
if ( ch != 'e' && ch != 's' && ch != '?' && ch != '>' )
3281+
{
3282+
throw new XmlPullParserException( "unexpected character " + printable( ch ), this, null );
3283+
}
3284+
32783285
if ( ch == 'e' )
32793286
{
3287+
if ( !isS( prevCh ) )
3288+
{
3289+
throw new XmlPullParserException( "expected a space after version and not " + printable( ch ), this,
3290+
null );
3291+
}
32803292
ch = more();
32813293
ch = requireInput( ch, NCODING );
32823294
ch = skipS( ch );

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

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void testibm_not_wf_P32_ibm32n03xml()
105105
}
106106
catch ( XmlPullParserException e )
107107
{
108-
assertTrue( e.getMessage().contains( "expected ?> as last part of <?xml not t" ) );
108+
assertTrue( e.getMessage().contains( "unexpected character S" ) );
109109
}
110110
}
111111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
package org.codehaus.plexus.util.xml.pull;
2+
3+
import static org.junit.Assert.assertTrue;
4+
import static org.junit.Assert.fail;
5+
6+
import java.io.File;
7+
import java.io.FileReader;
8+
import java.io.IOException;
9+
import java.io.Reader;
10+
11+
import org.junit.Before;
12+
import org.junit.Test;
13+
14+
/**
15+
* Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests.
16+
* TESCASES PROFILE: <pre>IBM XML Conformance Test Suite - Production 80</pre>
17+
* XML test files base folder: <pre>xmlconf/ibm/</pre>
18+
*
19+
* @author <a href="mailto:belingueres@gmail.com">Gabriel Belingueres</a>
20+
*/
21+
public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test
22+
{
23+
24+
final static File testResourcesDir = new File( "src/test/resources/", "xmlconf/ibm/" );
25+
26+
MXParser parser;
27+
28+
@Before
29+
public void setUp()
30+
{
31+
parser = new MXParser();
32+
}
33+
34+
/**
35+
* Test ID: <pre>ibm-not-wf-P80-ibm80n01.xml</pre>
36+
* Test URI: <pre>not-wf/P80/ibm80n01.xml</pre>
37+
* Comment: <pre>Tests EncodingDecl with a required field missing. The leading white space is missing in the EncodingDecl in the XMLDecl.</pre>
38+
* Sections: <pre>4.3.3</pre>
39+
* Version:
40+
*
41+
* @throws IOException if there is an I/O error
42+
*/
43+
@Test
44+
public void testibm_not_wf_P80_ibm80n01xml()
45+
throws IOException
46+
{
47+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n01.xml" ) ) )
48+
{
49+
parser.setInput( reader );
50+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
51+
;
52+
fail( "Tests EncodingDecl with a required field missing. The leading white space is missing in the EncodingDecl in the XMLDecl." );
53+
}
54+
catch ( XmlPullParserException e )
55+
{
56+
assertTrue( e.getMessage().contains( "expected a space after version and not e" ) );
57+
}
58+
}
59+
60+
/**
61+
* Test ID: <pre>ibm-not-wf-P80-ibm80n02.xml</pre>
62+
* Test URI: <pre>not-wf/P80/ibm80n02.xml</pre>
63+
* Comment: <pre>Tests EncodingDecl with a required field missing. The "=" sign is missing in the EncodingDecl in the XMLDecl.</pre>
64+
* Sections: <pre>4.3.3</pre>
65+
* Version:
66+
*
67+
* @throws IOException if there is an I/O error
68+
*/
69+
@Test
70+
public void testibm_not_wf_P80_ibm80n02xml()
71+
throws IOException
72+
{
73+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n02.xml" ) ) )
74+
{
75+
parser.setInput( reader );
76+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
77+
;
78+
fail( "Tests EncodingDecl with a required field missing. The \"=\" sign is missing in the EncodingDecl in the XMLDecl." );
79+
}
80+
catch ( XmlPullParserException e )
81+
{
82+
assertTrue( e.getMessage().contains( "expected equals sign (=) after encoding and not \"" ) );
83+
}
84+
}
85+
86+
/**
87+
* Test ID: <pre>ibm-not-wf-P80-ibm80n03.xml</pre>
88+
* Test URI: <pre>not-wf/P80/ibm80n03.xml</pre>
89+
* Comment: <pre>Tests EncodingDecl with a required field missing. The double quoted EncName are missing in the EncodingDecl in the XMLDecl.</pre>
90+
* Sections: <pre>4.3.3</pre>
91+
* Version:
92+
*
93+
* @throws IOException if there is an I/O error
94+
*/
95+
@Test
96+
public void testibm_not_wf_P80_ibm80n03xml()
97+
throws IOException
98+
{
99+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n03.xml" ) ) )
100+
{
101+
parser.setInput( reader );
102+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
103+
;
104+
fail( "Tests EncodingDecl with a required field missing. The double quoted EncName are missing in the EncodingDecl in the XMLDecl." );
105+
}
106+
catch ( XmlPullParserException e )
107+
{
108+
assertTrue( e.getMessage().contains( "expected apostrophe (') or quotation mark (\") after encoding and not ?" ) );
109+
}
110+
}
111+
112+
/**
113+
* Test ID: <pre>ibm-not-wf-P80-ibm80n04.xml</pre>
114+
* Test URI: <pre>not-wf/P80/ibm80n04.xml</pre>
115+
* Comment: <pre>Tests EncodingDecl with wrong field ordering. The string "encoding=" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl.</pre>
116+
* Sections: <pre>4.3.3</pre>
117+
* Version:
118+
*
119+
* @throws IOException if there is an I/O error
120+
*/
121+
@Test
122+
public void testibm_not_wf_P80_ibm80n04xml()
123+
throws IOException
124+
{
125+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n04.xml" ) ) )
126+
{
127+
parser.setInput( reader );
128+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
129+
;
130+
fail( "Tests EncodingDecl with wrong field ordering. The string \"encoding=\" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl." );
131+
}
132+
catch ( XmlPullParserException e )
133+
{
134+
assertTrue( e.getMessage().contains( "unexpected character \"" ) );
135+
}
136+
}
137+
138+
/**
139+
* Test ID: <pre>ibm-not-wf-P80-ibm80n05.xml</pre>
140+
* Test URI: <pre>not-wf/P80/ibm80n05.xml</pre>
141+
* Comment: <pre>Tests EncodingDecl with wrong field ordering. The "encoding" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl.</pre>
142+
* Sections: <pre>4.3.3</pre>
143+
* Version:
144+
*
145+
* @throws IOException if there is an I/O error
146+
*/
147+
@Test
148+
public void testibm_not_wf_P80_ibm80n05xml()
149+
throws IOException
150+
{
151+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n05.xml" ) ) )
152+
{
153+
parser.setInput( reader );
154+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
155+
;
156+
fail( "Tests EncodingDecl with wrong field ordering. The \"encoding\" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl." );
157+
}
158+
catch ( XmlPullParserException e )
159+
{
160+
assertTrue( e.getMessage().contains( "unexpected character \"" ) );
161+
}
162+
}
163+
164+
/**
165+
* Test ID: <pre>ibm-not-wf-P80-ibm80n06.xml</pre>
166+
* Test URI: <pre>not-wf/P80/ibm80n06.xml</pre>
167+
* Comment: <pre>Tests EncodingDecl with wrong key word. The string "Encoding" is used as the key word in the EncodingDecl in the XMLDecl.</pre>
168+
* Sections: <pre>4.3.3</pre>
169+
* Version:
170+
*
171+
* @throws IOException if there is an I/O error
172+
*/
173+
@Test
174+
public void testibm_not_wf_P80_ibm80n06xml()
175+
throws IOException
176+
{
177+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n06.xml" ) ) )
178+
{
179+
parser.setInput( reader );
180+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
181+
;
182+
fail( "Tests EncodingDecl with wrong key word. The string \"Encoding\" is used as the key word in the EncodingDecl in the XMLDecl." );
183+
}
184+
catch ( XmlPullParserException e )
185+
{
186+
assertTrue( e.getMessage().contains( "unexpected character E" ) );
187+
}
188+
}
189+
190+
}
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"encoding="UTF-8"?>
2+
<!--* missing white space in above EncodingDecl *-->
3+
<!DOCTYPE root
4+
[
5+
<!ELEMENT root (#PCDATA)>
6+
<!ATTLIST root att CDATA #IMPLIED>
7+
]>
8+
<root/>
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding "UTF-8"?>
2+
<!--* missing Eq in above EncodingDecl *-->
3+
<!DOCTYPE root
4+
[
5+
<!ELEMENT root (#PCDATA)>
6+
<!ATTLIST root att CDATA #IMPLIED>
7+
]>
8+
<root/>
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding= ?>
2+
<!--* missing EncName in above EncodingDecl *-->
3+
<!DOCTYPE root
4+
[
5+
<!ELEMENT root (#PCDATA)>
6+
<!ATTLIST root att CDATA #IMPLIED>
7+
]>
8+
<root/>
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" "UTF-8"encoding=?>
2+
<!--* wrong ordering in above EncodingDecl *-->
3+
<!DOCTYPE root
4+
[
5+
<!ELEMENT root (#PCDATA)>
6+
<!ATTLIST root att CDATA #IMPLIED>
7+
]>
8+
<root/>
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" "UTF-8"=encoding?>
2+
<!--* wrong ordering in above EncodingDecl *-->
3+
<!DOCTYPE root
4+
[
5+
<!ELEMENT root (#PCDATA)>
6+
<!ATTLIST root att CDATA #IMPLIED>
7+
]>
8+
<root/>
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" Encoding="UTF-8"?>
2+
<!--* Wrong keyword Encoding in above EncodingDecl *-->
3+
<!DOCTYPE root
4+
[
5+
<!ELEMENT root (#PCDATA)>
6+
<!ATTLIST root att CDATA #IMPLIED>
7+
]>
8+
<root/>

0 commit comments

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