Skip to content

Commit 841b5fa

Browse files
committed
IO-815: XmlStreamReader encoding RE is too strict
1 parent 18fa7cd commit 841b5fa

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ The <action> type attribute can be add,update,fix,remove.
4848

4949
<body>
5050
<release version="2.14.1" date="202Y-MM-DD" description="Java 8 is required.">
51+
<action dev="sebb" type="fix" issue="IO-810" due-to="Laurence Gonsalves">
52+
XmlStreamReader encoding match RE is too strict
53+
</action>
5154
<action dev="ggregory" type="fix" issue="IO-810" due-to="Gregor Dschung, Gary Gregory">
5255
Javadoc in FileUtils does not reflect code for thrown exceptions.
5356
</action>

src/main/java/org/apache/commons/io/input/XmlStreamReader.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,14 @@ public Builder setLenient(final boolean lenient) {
209209
// @formatter:off
210210
"^<\\?xml\\s+"
211211
+ "version\\s*=\\s*(?:(?:\"1\\.[0-9]+\")|(?:'1.[0-9]+'))\\s+"
212-
+ "encoding\\s*=\\s*((?:\"[A-Za-z]([A-Za-z0-9\\._]|-)*\")|(?:'[A-Za-z]([A-Za-z0-9\\\\._]|-)*'))",
212+
+ "encoding\\s*=\\s*"
213+
+ "((?:\"[A-Za-z0-9][A-Za-z0-9._+:-]*\")" // double-quoted
214+
+ "|(?:'[A-Za-z0-9][A-Za-z0-9._+:-]*'))", // single-quoted
213215
Pattern.MULTILINE);
216+
// N.B. the documented pattern is
217+
// EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
218+
// However this does not match all the aliases that are supported by Java.
219+
// e.g. '437', 'ISO_8859-1:1987' and 'ebcdic-de-273+euro'
214220
// @formatter:on
215221

216222
private static final String RAW_EX_1 = "Illegal encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch";

0 commit comments

Comments
 (0)