@@ -13,6 +13,17 @@ final class Tokeniser {
1313 static final char replacementChar = '\uFFFD' ; // replaces null character
1414 private static final char [] notCharRefCharsSorted = new char []{'\t' , '\n' , '\r' , '\f' , ' ' , '<' , '&' };
1515
16+ // Some illegal character escapes are parsed by browsers as windows-1252 instead. See issue #1034
17+ static final int win1252ExtensionsStart = 0x80 ;
18+ static final int [] win1252Extensions = new int [] {
19+ // we could build this manually, but Windows-1252 is not a standard java charset so that could break on
20+ // some platforms - this table is verified with a test
21+ 0x20AC , 0x0081 , 0x201A , 0x0192 , 0x201E , 0x2026 , 0x2020 , 0x2021 ,
22+ 0x02C6 , 0x2030 , 0x0160 , 0x2039 , 0x0152 , 0x008D , 0x017D , 0x008F ,
23+ 0x0090 , 0x2018 , 0x2019 , 0x201C , 0x201D , 0x2022 , 0x2013 , 0x2014 ,
24+ 0x02DC , 0x2122 , 0x0161 , 0x203A , 0x0153 , 0x009D , 0x017E , 0x0178 ,
25+ };
26+
1627 static {
1728 Arrays .sort (notCharRefCharsSorted );
1829 }
@@ -148,6 +159,12 @@ int[] consumeCharacterReference(Character additionalAllowedCharacter, boolean in
148159 codeRef [0 ] = replacementChar ;
149160 return codeRef ;
150161 } else {
162+ // fix illegal unicode characters to match browser behavior
163+ if (charval >= win1252ExtensionsStart && charval < win1252ExtensionsStart + win1252Extensions .length ) {
164+ characterReferenceError ("character is not a valid unicode code point" );
165+ charval = win1252Extensions [charval - win1252ExtensionsStart ];
166+ }
167+
151168 // todo: implement number replacement table
152169 // todo: check for extra illegal unicode points as parse errors
153170 codeRef [0 ] = charval ;
0 commit comments