Skip to content

Instantly share code, notes, and snippets.

Created July 18, 2012 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3135601 to your computer and use it in GitHub Desktop.
Save anonymous/3135601 to your computer and use it in GitHub Desktop.
diff -r de960161c5f1 src/nu/validator/xml/ContentTypeParser.java
--- a/src/nu/validator/xml/ContentTypeParser.java Thu Jul 21 17:58:26 2011 +0300
+++ b/src/nu/validator/xml/ContentTypeParser.java Wed Jul 18 20:15:01 2012 +0900
@@ -34,8 +34,8 @@
public class ContentTypeParser {
- private static final Pattern CHARSET = Pattern.compile("^\\s*charset\\s*=\\s*(\\S+)\\s*$");
-
+ private static final Pattern CHARSET = Pattern.compile("^\\s*charset\\s*=\\s*(?:\"([^\"\\s]+)\")|([^\"\\s]+)\\s*$");
+
private final ErrorHandler errorHandler;
private boolean laxContentType;
@@ -209,7 +209,11 @@
for (int i = 1; i < params.length; i++) {
Matcher matcher = CHARSET.matcher(params[i]);
if (matcher.matches()) {
- charset = matcher.group(1);
+ if (matcher.start(1) != -1) {
+ charset = matcher.group(1);
+ } else {
+ charset = matcher.group(2);
+ }
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment