Skip to content

Commit

Permalink
Better regular expression
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jul 24, 2023
1 parent 3c9d7bc commit 06fde31
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/org/apache/commons/io/input/XmlStreamReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,17 @@ public Builder setLenient(final boolean lenient) {

/**
* Pattern capturing the encoding of the "xml" processing instruction.
* <p>
* See also the <a href="https://www.w3.org/TR/2008/REC-xml-20081126/#NT-EncName">XML specification</a>.
* </p>
*/
public static final Pattern ENCODING_PATTERN = Pattern.compile("^<\\?xml.*encoding[\\s]*=[\\s]*((?:\".[^\"]*\")|(?:'.[^']*'))", Pattern.MULTILINE);
public static final Pattern ENCODING_PATTERN = Pattern.compile(
// @formatter:off
"^<\\?xml\\s+"
+ "version\\s*=\\s*(?:(?:\"1\\.[0-9]+\")|(?:'1.[0-9]+'))\\s+"
+ "encoding\\s*=\\s*((?:\"[A-Za-z]([A-Za-z0-9\\._]|-)*\")|(?:'[A-Za-z]([A-Za-z0-9\\\\._]|-)*'))",
Pattern.MULTILINE);
// @formatter:on

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

Expand Down

0 comments on commit 06fde31

Please sign in to comment.