Skip to content

Commit beb060b

Browse files
Conform encoding-label matching to Encoding spec
This change makes the parser’s encoding-name matching conform to the current Encoding spec at https://encoding.spec.whatwg.org/#concept-encoding-get — which requires that only leading and trailing whitespace be removed from a string before checking if it matches any valid encoding name. Otherwise, without this change, the parser instead implements https://www.unicode.org/reports/tr22/tr22-8.html#Charset_Alias_Matching — which requires deleting “all characters except a-z, A-Z, and 0-9” from a string before checking if it matches any valid encoding name. That difference makes us fail two html5-tests cases. Relates to #47
1 parent 8c62d2d commit beb060b

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/nu/validator/htmlparser/io/Encoding.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,7 @@ public static String toNameKey(String str) {
417417
if (c >= 'A' && c <= 'Z') {
418418
c += 0x20;
419419
}
420-
if (!((c >= '\t' && c <= '\r') || (c >= '\u0020' && c <= '\u002F')
421-
|| (c >= '\u003A' && c <= '\u0040')
422-
|| (c >= '\u005B' && c <= '\u0060') || (c >= '\u007B' && c <= '\u007E'))) {
420+
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')) {
423421
buf[j] = c;
424422
j++;
425423
}

0 commit comments

Comments
 (0)