Skip to content

Commit 724c56d

Browse files
authored
Fix MXParser not failing when space is missing in xml declaration (#128) (#129)
fix #128
1 parent 761ac42 commit 724c56d

File tree

11 files changed

+326
-1
lines changed

11 files changed

+326
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3113,7 +3113,7 @@ else if ( ch == '<' )
31133113
piTargetEnd = pos - 1;
31143114

31153115
// [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
3116-
if ( ( piTargetEnd - piTargetStart ) == 3 )
3116+
if ( ( piTargetEnd - piTargetStart ) >= 3 )
31173117
{
31183118
if ( ( buf[piTargetStart] == 'x' || buf[piTargetStart] == 'X' )
31193119
&& ( buf[piTargetStart + 1] == 'm' || buf[piTargetStart + 1] == 'M' )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
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.FileNotFoundException;
8+
import java.io.FileReader;
9+
import java.io.IOException;
10+
import java.io.Reader;
11+
12+
import org.junit.Before;
13+
import org.junit.Test;
14+
15+
/**
16+
* Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests.
17+
* TESCASES PROFILE: <pre>IBM XML Conformance Test Suite - Production 24</pre>
18+
* XML test files base folder: <pre>xmlconf/ibm/</pre>
19+
*
20+
* @author <a href="mailto:belingueres@gmail.com">Gabriel Belingueres</a>
21+
*/
22+
public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test
23+
{
24+
25+
final static File testResourcesDir = new File( "src/test/resources/", "xmlconf/ibm/" );
26+
27+
MXParser parser;
28+
29+
@Before
30+
public void setUp()
31+
{
32+
parser = new MXParser();
33+
}
34+
35+
/**
36+
* Test ID: <pre>ibm-not-wf-P24-ibm24n01.xml</pre>
37+
* Test URI: <pre>not-wf/P24/ibm24n01.xml</pre>
38+
* Comment: <pre>Tests VersionInfo with a required field missing. The VersionNum is missing in the VersionInfo in the XMLDecl.</pre>
39+
* Sections: <pre>2.8</pre>
40+
* Version:
41+
*
42+
* @throws IOException if there is an I/O error
43+
*/
44+
@Test
45+
public void testibm_not_wf_P24_ibm24n01xml()
46+
throws IOException
47+
{
48+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n01.xml" ) ) )
49+
{
50+
parser.setInput( reader );
51+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
52+
;
53+
fail( "Tests VersionInfo with a required field missing. The VersionNum is missing in the VersionInfo in the XMLDecl." );
54+
}
55+
catch ( XmlPullParserException e )
56+
{
57+
assertTrue( e.getMessage().contains( "expected apostrophe (') or quotation mark (\") after version and not ?" ) );
58+
}
59+
}
60+
61+
/**
62+
* Test ID: <pre>ibm-not-wf-P24-ibm24n02.xml</pre>
63+
* Test URI: <pre>not-wf/P24/ibm24n02.xml</pre>
64+
* Comment: <pre>Tests VersionInfo with a required field missing. The white space is missing between the key word "xml" and the VersionInfo in the XMLDecl.</pre>
65+
* Sections: <pre>2.8</pre>
66+
* Version:
67+
*
68+
* @throws XmlPullParserException if there is a problem parsing the XML file
69+
* @throws FileNotFoundException if the testing XML file is not found
70+
* @throws IOException if there is an I/O error
71+
*/
72+
@Test
73+
public void testibm_not_wf_P24_ibm24n02xml()
74+
throws IOException
75+
{
76+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n02.xml" ) ) )
77+
{
78+
parser.setInput( reader );
79+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
80+
;
81+
fail( "Tests VersionInfo with a required field missing. The white space is missing between the key word \"xml\" and the VersionInfo in the XMLDecl." );
82+
}
83+
catch ( XmlPullParserException e )
84+
{
85+
assertTrue( e.getMessage().contains( "expected v in version and not ?" ) );
86+
}
87+
}
88+
89+
/**
90+
* Test ID: <pre>ibm-not-wf-P24-ibm24n03.xml</pre>
91+
* Test URI: <pre>not-wf/P24/ibm24n03.xml</pre>
92+
* Comment: <pre>Tests VersionInfo with a required field missing. The "=" (equal sign) is missing between the key word "version" and the VersionNum.</pre>
93+
* Sections: <pre>2.8</pre>
94+
* Version:
95+
*
96+
* @throws IOException if there is an I/O error
97+
*/
98+
@Test
99+
public void testibm_not_wf_P24_ibm24n03xml()
100+
throws IOException
101+
{
102+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n03.xml" ) ) )
103+
{
104+
parser.setInput( reader );
105+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
106+
;
107+
fail( "Tests VersionInfo with a required field missing. The \"=\" (equal sign) is missing between the key word \"version\" and the VersionNum." );
108+
}
109+
catch ( XmlPullParserException e )
110+
{
111+
assertTrue( e.getMessage().contains( "expected equals sign (=) after version and not \\'" ) );
112+
}
113+
}
114+
115+
/**
116+
* Test ID: <pre>ibm-not-wf-P24-ibm24n04.xml</pre>
117+
* Test URI: <pre>not-wf/P24/ibm24n04.xml</pre>
118+
* Comment: <pre>Tests VersionInfo with wrong field ordering. The VersionNum occurs before "=" and "version".</pre>
119+
* Sections: <pre>2.8</pre>
120+
* Version:
121+
*
122+
* @throws IOException if there is an I/O error
123+
*/
124+
@Test
125+
public void testibm_not_wf_P24_ibm24n04xml()
126+
throws IOException
127+
{
128+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n04.xml" ) ) )
129+
{
130+
parser.setInput( reader );
131+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
132+
;
133+
fail( "Tests VersionInfo with wrong field ordering. The VersionNum occurs before \"=\" and \"version\"." );
134+
}
135+
catch ( XmlPullParserException e )
136+
{
137+
assertTrue( e.getMessage().contains( "expected v in version and not \\'" ) );
138+
}
139+
}
140+
141+
/**
142+
* Test ID: <pre>ibm-not-wf-P24-ibm24n05.xml</pre>
143+
* Test URI: <pre>not-wf/P24/ibm24n05.xml</pre>
144+
* Comment: <pre>Tests VersionInfo with wrong field ordering. The "=" occurs after "version" and the VersionNum.</pre>
145+
* Sections: <pre>2.8</pre>
146+
* Version:
147+
*
148+
* @throws IOException if there is an I/O error
149+
*/
150+
@Test
151+
public void testibm_not_wf_P24_ibm24n05xml()
152+
throws IOException
153+
{
154+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n05.xml" ) ) )
155+
{
156+
parser.setInput( reader );
157+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
158+
;
159+
fail( "Tests VersionInfo with wrong field ordering. The \"=\" occurs after \"version\" and the VersionNum." );
160+
}
161+
catch ( XmlPullParserException e )
162+
{
163+
assertTrue( e.getMessage().contains( "expected equals sign (=) after version and not \\'" ) );
164+
}
165+
}
166+
167+
/**
168+
* Test ID: <pre>ibm-not-wf-P24-ibm24n06.xml</pre>
169+
* Test URI: <pre>not-wf/P24/ibm24n06.xml</pre>
170+
* Comment: <pre>Tests VersionInfo with the wrong key word "Version".</pre>
171+
* Sections: <pre>2.8</pre>
172+
* Version:
173+
*
174+
* @throws IOException if there is an I/O error
175+
*/
176+
@Test
177+
public void testibm_not_wf_P24_ibm24n06xml()
178+
throws IOException
179+
{
180+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n06.xml" ) ) )
181+
{
182+
parser.setInput( reader );
183+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
184+
;
185+
fail( "Tests VersionInfo with the wrong key word \"Version\"." );
186+
}
187+
catch ( XmlPullParserException e )
188+
{
189+
assertTrue( e.getMessage().contains( "expected v in version and not V" ) );
190+
}
191+
}
192+
193+
/**
194+
* Test ID: <pre>ibm-not-wf-P24-ibm24n07.xml</pre>
195+
* Test URI: <pre>not-wf/P24/ibm24n07.xml</pre>
196+
* Comment: <pre>Tests VersionInfo with the wrong key word "versioN".</pre>
197+
* Sections: <pre>2.8</pre>
198+
* Version:
199+
*
200+
* @throws IOException if there is an I/O error
201+
*/
202+
@Test
203+
public void testibm_not_wf_P24_ibm24n07xml()
204+
throws IOException
205+
{
206+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n07.xml" ) ) )
207+
{
208+
parser.setInput( reader );
209+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
210+
;
211+
fail( "Tests VersionInfo with the wrong key word \"versioN\"." );
212+
}
213+
catch ( XmlPullParserException e )
214+
{
215+
assertTrue( e.getMessage().contains( "expected n in version and not N" ) );
216+
}
217+
}
218+
219+
/**
220+
* Test ID: <pre>ibm-not-wf-P24-ibm24n08.xml</pre>
221+
* Test URI: <pre>not-wf/P24/ibm24n08.xml</pre>
222+
* Comment: <pre>Tests VersionInfo with mismatched quotes around the VersionNum. version = '1.0" is used as the VersionInfo.</pre>
223+
* Sections: <pre>2.8</pre>
224+
* Version:
225+
*
226+
* @throws IOException if there is an I/O error
227+
*/
228+
@Test
229+
public void testibm_not_wf_P24_ibm24n08xml()
230+
throws IOException
231+
{
232+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n08.xml" ) ) )
233+
{
234+
parser.setInput( reader );
235+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
236+
;
237+
fail( "Tests VersionInfo with mismatched quotes around the VersionNum. version = '1.0\" is used as the VersionInfo." );
238+
}
239+
catch ( XmlPullParserException e )
240+
{
241+
assertTrue( e.getMessage().contains( "<?xml version value expected to be in ([a-zA-Z0-9_.:] | '-') not \"" ) );
242+
}
243+
}
244+
245+
/**
246+
* Test ID: <pre>ibm-not-wf-P24-ibm24n09.xml</pre>
247+
* Test URI: <pre>not-wf/P24/ibm24n09.xml</pre>
248+
* Comment: <pre>Tests VersionInfo with mismatched quotes around the VersionNum. The closing bracket for the VersionNum is missing.</pre>
249+
* Sections: <pre>2.8</pre>
250+
* Version:
251+
*
252+
* @throws IOException if there is an I/O error
253+
*/
254+
@Test
255+
public void testibm_not_wf_P24_ibm24n09xml()
256+
throws IOException
257+
{
258+
try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n09.xml" ) ) )
259+
{
260+
parser.setInput( reader );
261+
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
262+
;
263+
fail( "Tests VersionInfo with mismatched quotes around the VersionNum. The closing bracket for the VersionNum is missing." );
264+
}
265+
catch ( XmlPullParserException e )
266+
{
267+
assertTrue( e.getMessage().contains( "<?xml version value expected to be in ([a-zA-Z0-9_.:] | '-') not " ) );
268+
}
269+
}
270+
271+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version= ?>
2+
<!DOCTYPE doc [
3+
<!ELEMENT doc EMPTY>
4+
]>
5+
<doc/>
6+
<!-- VersioNum is missing in VersionInfo -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xmlversion='1.0' ?>
2+
<!DOCTYPE doc [
3+
<!ELEMENT doc EMPTY>
4+
]>
5+
<doc/>
6+
<!-- S is missing in VersionInfo -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version'1.0' ?>
2+
<!DOCTYPE doc [
3+
<!ELEMENT doc EMPTY>
4+
]>
5+
<doc/>
6+
<!-- Eq is missing in VersionInfo -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml '1.0'=version ?>
2+
<!DOCTYPE doc [
3+
<!ELEMENT doc EMPTY>
4+
]>
5+
<doc/>
6+
<!-- Wrong ordering VersionNum Eq 'version' -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version'1.0'= ?>
2+
<!DOCTYPE doc [
3+
<!ELEMENT doc EMPTY>
4+
]>
5+
<doc/>
6+
<!-- Wrong ordering version VersionNum Eq -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml Version='1.0' ?>
2+
<!DOCTYPE doc [
3+
<!ELEMENT doc EMPTY>
4+
]>
5+
<doc/>
6+
<!-- Wrong key word 'Version' -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml versioN='1.0' ?>
2+
<!DOCTYPE doc [
3+
<!ELEMENT doc EMPTY>
4+
]>
5+
<doc/>
6+
<!-- Wrong key word 'versioN' -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0" ?>
2+
<!DOCTYPE doc [
3+
<!ELEMENT doc EMPTY>
4+
]>
5+
<doc/>
6+
<!-- Mismatched qotes in VersionInfo -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0 ?>
2+
<!DOCTYPE doc [
3+
<!ELEMENT doc EMPTY>
4+
]>
5+
<doc/>
6+
<!-- Mismatched qotes in VersionInfo -->

0 commit comments

Comments
 (0)