-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- when parsing large char entities. - when mixing invalid encoding declarations and file encodings.
- Loading branch information
1 parent
48e444f
commit 1e18ddc
Showing
13 changed files
with
399 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
278 changes: 278 additions & 0 deletions
278
...g/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
package org.codehaus.plexus.util.xml.pull; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests. | ||
* TESCASES PROFILE: <pre>Bjoern Hoehrmann via HST 2013-09-18</pre> | ||
* XML test files base folder: <pre>xmlconf/eduni/misc/</pre> | ||
* | ||
* @author <a href="mailto:belingueres@gmail.com">Gabriel Belingueres</a> | ||
*/ | ||
public class eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test | ||
{ | ||
|
||
final static File testResourcesDir = new File("src/test/resources/", "xmlconf/eduni/misc/"); | ||
|
||
MXParser parser; | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
parser = new MXParser(); | ||
} | ||
|
||
/** | ||
* Test ID: <pre>hst-bh-001</pre> | ||
* Test URI: <pre>001.xml</pre> | ||
* Comment: <pre>decimal charref &#62; 10FFFF, indeed &#62; max 32 bit integer, checking for recovery from possible overflow</pre> | ||
* Sections: <pre>2.2 [2], 4.1 [66]</pre> | ||
* Version: | ||
* | ||
* @throws IOException if there is an I/O error | ||
*/ | ||
@Test | ||
public void testhst_bh_001() | ||
throws IOException | ||
{ | ||
try ( Reader reader = new FileReader( new File( testResourcesDir, "001.xml" ) ) ) | ||
{ | ||
parser.setInput( reader ); | ||
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) | ||
; | ||
fail( "decimal charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow" ); | ||
} | ||
catch ( XmlPullParserException e ) | ||
{ | ||
assertTrue( e.getMessage().contains( "character reference (with hex value FF000000F6) is invalid" ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Test ID: <pre>hst-bh-002</pre> | ||
* Test URI: <pre>002.xml</pre> | ||
* Comment: <pre>hex charref &#62; 10FFFF, indeed &#62; max 32 bit integer, checking for recovery from possible overflow</pre> | ||
* Sections: <pre>2.2 [2], 4.1 [66]</pre> | ||
* Version: | ||
* | ||
* @throws IOException if there is an I/O error | ||
*/ | ||
@Test | ||
public void testhst_bh_002() | ||
throws IOException | ||
{ | ||
try ( Reader reader = new FileReader( new File( testResourcesDir, "002.xml" ) ) ) | ||
{ | ||
parser.setInput( reader ); | ||
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) | ||
; | ||
fail( "hex charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow" ); | ||
} | ||
catch ( XmlPullParserException e ) | ||
{ | ||
assertTrue( e.getMessage().contains( "character reference (with decimal value 4294967542) is invalid" ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Test ID: <pre>hst-bh-003</pre> | ||
* Test URI: <pre>003.xml</pre> | ||
* Comment: <pre>decimal charref &#62; 10FFFF, indeed &#62; max 64 bit integer, checking for recovery from possible overflow</pre> | ||
* Sections: <pre>2.2 [2], 4.1 [66]</pre> | ||
* Version: | ||
* | ||
* @throws IOException if there is an I/O error | ||
*/ | ||
@Test | ||
public void testhst_bh_003() | ||
throws IOException | ||
{ | ||
try ( Reader reader = new FileReader( new File( testResourcesDir, "003.xml" ) ) ) | ||
{ | ||
parser.setInput( reader ); | ||
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) | ||
; | ||
fail( "decimal charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow" ); | ||
} | ||
catch ( XmlPullParserException e ) | ||
{ | ||
assertTrue( e.getMessage().contains( "character reference (with hex value FFFFFFFF000000F6) is invalid" ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Test ID: <pre>hst-bh-004</pre> | ||
* Test URI: <pre>004.xml</pre> | ||
* Comment: <pre>hex charref &#62; 10FFFF, indeed &#62; max 64 bit integer, checking for recovery from possible overflow</pre> | ||
* Sections: <pre>2.2 [2], 4.1 [66]</pre> | ||
* Version: | ||
* | ||
* @throws IOException if there is an I/O error | ||
*/ | ||
@Test | ||
public void testhst_bh_004() | ||
throws IOException | ||
{ | ||
try ( Reader reader = new FileReader( new File( testResourcesDir, "004.xml" ) ) ) | ||
{ | ||
parser.setInput( reader ); | ||
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) | ||
; | ||
fail( "hex charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow" ); | ||
} | ||
catch ( XmlPullParserException e ) | ||
{ | ||
assertTrue( e.getMessage().contains( "character reference (with decimal value 18446744073709551862) is invalid" ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Test ID: <pre>hst-bh-005</pre> | ||
* Test URI: <pre>005.xml</pre> | ||
* Comment: <pre>xmlns:xml is an attribute as far as validation is concerned and must be declared</pre> | ||
* Sections: <pre>3.1 [41]</pre> | ||
* Version: | ||
* | ||
* @throws IOException if there is an I/O error | ||
* | ||
* NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing. | ||
*/ | ||
// @Test | ||
public void testhst_bh_005() | ||
throws IOException | ||
{ | ||
try ( Reader reader = new FileReader( new File( testResourcesDir, "005.xml" ) ) ) | ||
{ | ||
parser.setInput( reader ); | ||
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) | ||
; | ||
fail( "xmlns:xml is an attribute as far as validation is concerned and must be declared" ); | ||
} | ||
catch ( XmlPullParserException e ) | ||
{ | ||
assertTrue( true ); | ||
} | ||
} | ||
|
||
/** | ||
* Test ID: <pre>hst-bh-006</pre> | ||
* Test URI: <pre>006.xml</pre> | ||
* Comment: <pre>xmlns:foo is an attribute as far as validation is concerned and must be declared</pre> | ||
* Sections: <pre>3.1 [41]</pre> | ||
* Version: | ||
* | ||
* @throws IOException if there is an I/O error | ||
* | ||
* NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing. | ||
*/ | ||
// @Test | ||
public void testhst_bh_006() | ||
throws IOException | ||
{ | ||
try ( Reader reader = new FileReader( new File( testResourcesDir, "006.xml" ) ) ) | ||
{ | ||
parser.setInput( reader ); | ||
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) | ||
; | ||
fail( "xmlns:foo is an attribute as far as validation is concerned and must be declared" ); | ||
} | ||
catch ( XmlPullParserException e ) | ||
{ | ||
assertTrue( true ); | ||
} | ||
} | ||
|
||
/** | ||
* Test ID: <pre>hst-lhs-007</pre> | ||
* Test URI: <pre>007.xml</pre> | ||
* Comment: <pre>UTF-8 BOM plus xml decl of iso-8859-1 incompatible</pre> | ||
* Sections: <pre>4.3.3</pre> | ||
* Version: | ||
* | ||
* @throws IOException if there is an I/O error | ||
*/ | ||
@Test | ||
public void testhst_lhs_007() | ||
throws IOException | ||
{ | ||
try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "007.xml" ) ); | ||
InputStreamReader reader = new InputStreamReader( is, StandardCharsets.UTF_8 ) ) | ||
{ | ||
parser.setInput( reader ); | ||
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) | ||
; | ||
fail( "UTF-8 BOM plus xml decl of iso-8859-1 incompatible" ); | ||
} | ||
catch ( XmlPullParserException e ) | ||
{ | ||
assertTrue( e.getMessage().contains( "UTF-8 BOM plus xml decl of iso-8859-1 is incompatible" ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Test ID: <pre>hst-lhs-008</pre> | ||
* Test URI: <pre>008.xml</pre> | ||
* Comment: <pre>UTF-16 BOM plus xml decl of utf-8 (using UTF-16 coding) incompatible</pre> | ||
* Sections: <pre>4.3.3</pre> | ||
* Version: | ||
* | ||
* @throws IOException if there is an I/O error | ||
*/ | ||
@Test | ||
public void testhst_lhs_008() | ||
throws IOException | ||
{ | ||
try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "008.xml" ) ); | ||
InputStreamReader reader = new InputStreamReader( is, StandardCharsets.UTF_16 ) ) | ||
{ | ||
parser.setInput( reader ); | ||
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) | ||
; | ||
fail( "UTF-16 BOM plus xml decl of utf-8 (using UTF-16 coding) incompatible" ); | ||
} | ||
catch ( XmlPullParserException e ) | ||
{ | ||
assertTrue( e.getMessage().contains( "UTF-16 BOM plus xml decl of utf-8 is incompatible" ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Test ID: <pre>hst-lhs-009</pre> | ||
* Test URI: <pre>009.xml</pre> | ||
* Comment: <pre>UTF-16 BOM plus xml decl of utf-8 (using UTF-8 coding) incompatible</pre> | ||
* Sections: <pre>4.3.3</pre> | ||
* Version: | ||
* | ||
* @throws IOException if there is an I/O error | ||
*/ | ||
@Test | ||
public void testhst_lhs_009() | ||
throws IOException | ||
{ | ||
try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "009.xml" ) ); | ||
InputStreamReader reader = new InputStreamReader( is, StandardCharsets.UTF_8 ) ) | ||
{ | ||
parser.setInput( reader ); | ||
while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) | ||
; | ||
fail( "UTF-16 BOM plus xml decl of utf-8 (using UTF-8 coding) incompatible" ); | ||
} | ||
catch ( XmlPullParserException e ) | ||
{ | ||
assertTrue( e.getMessage().contains( "UTF-16 BOM in a UTF-8 encoded file is incompatible" ) ); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!DOCTYPE p [ | ||
<!ELEMENT p (#PCDATA)> | ||
]> | ||
<p>Fa�il</p> <!-- 32 bit integer overflow --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!DOCTYPE p [ | ||
<!ELEMENT p (#PCDATA)> | ||
]> | ||
<p>Fa�il</p> <!-- 32 bit integer overflow --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!DOCTYPE p [ | ||
<!ELEMENT p (#PCDATA)> | ||
]> | ||
<p>Fa�il</p> <!-- 64 bit integer overflow --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!DOCTYPE p [ | ||
<!ELEMENT p (#PCDATA)> | ||
]> | ||
<p>Fa�il</p> <!-- 64 bit integer overflow --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!DOCTYPE x [ <!ELEMENT x EMPTY> ]> | ||
<x xmlns:xml='http://www.w3.org/XML/1998/namespace'/> |
Oops, something went wrong.
1e18ddc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just hit a regression with this change. Maven Doxia Sitetools from fail with 3.4.0, it says:
@belingueres Can you check?
1e18ddc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1e18ddc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot confirm:
1e18ddc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1e18ddc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No actions required, I need to understand why cause and figure out what we have done wrong. If you have an idea how to fix this inside Sitetools, I'd be grateful.
1e18ddc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue has been addressed in 3.4.2.