Skip to content

Commit

Permalink
Conform encoding-label matching to Encoding spec
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sideshowbarker committed Sep 13, 2020
1 parent 8c62d2d commit beb060b
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/nu/validator/htmlparser/io/Encoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,7 @@ public static String toNameKey(String str) {
if (c >= 'A' && c <= 'Z') {
c += 0x20;
}
if (!((c >= '\t' && c <= '\r') || (c >= '\u0020' && c <= '\u002F')
|| (c >= '\u003A' && c <= '\u0040')
|| (c >= '\u005B' && c <= '\u0060') || (c >= '\u007B' && c <= '\u007E'))) {
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')) {
buf[j] = c;
j++;
}
Expand Down

0 comments on commit beb060b

Please sign in to comment.