diff --git a/checkstyle_suppressions.xml b/checkstyle_suppressions.xml index 2a88e896a6..b84cdfc765 100644 --- a/checkstyle_suppressions.xml +++ b/checkstyle_suppressions.xml @@ -50,7 +50,10 @@ + + + diff --git a/src/test/java/org/htmlunit/javascript/host/xml/AbstractXMLHttpRequestEncodingTest.java b/src/test/java/org/htmlunit/javascript/host/xml/AbstractXMLHttpRequestEncodingTest.java index d19baf41a1..b97b1cee2a 100644 --- a/src/test/java/org/htmlunit/javascript/host/xml/AbstractXMLHttpRequestEncodingTest.java +++ b/src/test/java/org/htmlunit/javascript/host/xml/AbstractXMLHttpRequestEncodingTest.java @@ -19,6 +19,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.util.Locale; import org.apache.commons.io.ByteOrderMark; import org.apache.commons.lang3.ArrayUtils; @@ -44,6 +45,8 @@ public enum TestCharset { UTF8("UTF8", UTF_8), /** iso 8859 1. */ ISO88591("ISO88591", ISO_8859_1), + /** windows-1250. */ + WINDOWS1250("WINDOWS1250", Charset.forName("windows-1250")), /** gb 2312. */ GB2312("GB2312", Charset.forName("GB2312")); @@ -114,4 +117,12 @@ protected void setupXmlResponse(final String xml, final String bom, final TestMi getMockWebConnection().setResponse(URL_SECOND, xml, mimeTypeXml.getMimeType(), charsetXmlResponseHeader == null ? null : charsetXmlResponseHeader.getCharset()); } + + protected static String escape(final String str) { + final StringBuilder res = new StringBuilder(); + for (final char c : str.toCharArray()) { + res.append("\\u").append(String.format("%04X", (int) c).toLowerCase(Locale.ROOT)); + } + return res.toString(); + } } diff --git a/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequestResponseAsTextEncodingTest.java b/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequestResponseAsTextEncodingTest.java index abeb7ab3b5..665836a443 100644 --- a/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequestResponseAsTextEncodingTest.java +++ b/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequestResponseAsTextEncodingTest.java @@ -46,10 +46,10 @@ public static Collection data() throws Exception { final String[] xmlEncodingHeaders = {"", "utf8"}; final TestCharset[] charsetHtmlResponseHeaders = - new TestCharset[] {null, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.GB2312}; + new TestCharset[] {null, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.WINDOWS1250, TestCharset.GB2312}; final TestMimeType[] mimeTypeXmls = {TestMimeType.EMPTY, TestMimeType.XML, TestMimeType.PLAIN}; final TestCharset[] charsetXmlResponseHeaders = - new TestCharset[] {null, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.GB2312}; + new TestCharset[] {null, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.WINDOWS1250, TestCharset.GB2312}; final String[] boms = {null, BOM_UTF_8, BOM_UTF_16LE, BOM_UTF_16BE}; for (final Object xmlEncodingHeader : xmlEncodingHeaders) { @@ -139,13 +139,23 @@ private void responseText( + " \n" + " \n" + " \n" @@ -155,7 +165,7 @@ private void responseText( final String xml = "" + "" + "a" - + "\u00E4" + + "\u008A\u009A\u00E4\u00A9" + "\u0623\u0647\u0644\u0627\u064B" + "\u043C\u0438\u0440" + "\u623F\u95F4" @@ -164,36 +174,41 @@ private void responseText( String[] expected = getExpectedAlerts(); if (expected == null || expected.length == 0) { expected = new String[] { - "aä??????????"}; + escape("") + + "\\u003c\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e\\u003c\\u0063\\u0031\\u003e\\u0061\\u003c\\u002f\\u0063\\u0031\\u003e\\u003c\\u0063\\u0032\\u003e\\u0160\\u0161\\u00e4\\u00a9\\u003c\\u002f\\u0063\\u0032\\u003e\\u003c\\u0063\\u0033\\u003e\\u003f\\u003f\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0033\\u003e\\u003c\\u0063\\u0034\\u003e\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0034\\u003e\\u003c\\u0063\\u0035\\u003e\\u003f\\u003f\\u003c\\u002f\\u0063\\u0035\\u003e\\u003c\\u002f\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e"}; if (TestCharset.UTF8.equals(charsetXmlResponseHeader) || bom != null) { expected = new String[] { - "aäأهلاًмир房间"}; + escape("") + + "\\u003c\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e\\u003c\\u0063\\u0031\\u003e\\u0061\\u003c\\u002f\\u0063\\u0031\\u003e\\u003c\\u0063\\u0032\\u003e\\u008a\\u009a\\u00e4\\u00a9\\u003c\\u002f\\u0063\\u0032\\u003e\\u003c\\u0063\\u0033\\u003e\\u0623\\u0647\\u0644\\u0627\\u064b\\u003c\\u002f\\u0063\\u0033\\u003e\\u003c\\u0063\\u0034\\u003e\\u043c\\u0438\\u0440\\u003c\\u002f\\u0063\\u0034\\u003e\\u003c\\u0063\\u0035\\u003e\\u623f\\u95f4\\u003c\\u002f\\u0063\\u0035\\u003e\\u003c\\u002f\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e"}; } else if (TestMimeType.EMPTY.equals(mimeTypeXml)) { if (TestCharset.GB2312.equals(charsetXmlResponseHeader)) { expected = new String[] { - "a??????�ާڧ�����"}; + escape("") + + "\\u003c\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e\\u003c\\u0063\\u0031\\u003e\\u0061\\u003c\\u002f\\u0063\\u0031\\u003e\\u003c\\u0063\\u0032\\u003e\\u003f\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0032\\u003e\\u003c\\u0063\\u0033\\u003e\\u003f\\u003f\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0033\\u003e\\u003c\\u0063\\u0034\\u003e\\ufffd\\u07a7\\u06a7\\ufffd\\u003c\\u002f\\u0063\\u0034\\u003e\\u003c\\u0063\\u0035\\u003e\\ufffd\\ufffd\\ufffd\\ufffd\\u003c\\u002f\\u0063\\u0035\\u003e\\u003c\\u002f\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e"}; + } + else if (TestCharset.WINDOWS1250.equals(charsetXmlResponseHeader)) { + expected = new String[] { + escape("") + + "\\u003c\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e\\u003c\\u0063\\u0031\\u003e\\u0061\\u003c\\u002f\\u0063\\u0031\\u003e\\u003c\\u0063\\u0032\\u003e\\u003f\\u003f\\ufffd\\u003c\\u002f\\u0063\\u0032\\u003e\\u003c\\u0063\\u0033\\u003e\\u003f\\u003f\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0033\\u003e\\u003c\\u0063\\u0034\\u003e\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0034\\u003e\\u003c\\u0063\\u0035\\u003e\\u003f\\u003f\\u003c\\u002f\\u0063\\u0035\\u003e\\u003c\\u002f\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e"}; } else if (null == charsetXmlResponseHeader || TestCharset.ISO88591.equals(charsetXmlResponseHeader)) { expected = new String[] { - "a??????????"}; + escape("") + + "\\u003c\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e\\u003c\\u0063\\u0031\\u003e\\u0061\\u003c\\u002f\\u0063\\u0031\\u003e\\u003c\\u0063\\u0032\\u003e\\ufffd\\ufffd\\ufffd\\u003c\\u002f\\u0063\\u0032\\u003e\\u003c\\u0063\\u0033\\u003e\\u003f\\u003f\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0033\\u003e\\u003c\\u0063\\u0034\\u003e\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0034\\u003e\\u003c\\u0063\\u0035\\u003e\\u003f\\u003f\\u003c\\u002f\\u0063\\u0035\\u003e\\u003c\\u002f\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e"}; } } else if (TestMimeType.PLAIN.equals(mimeTypeXml) || TestMimeType.XML.equals(mimeTypeXml)) { if (TestCharset.GB2312.equals(charsetXmlResponseHeader)) { expected = new String[] { - "a??????мир房间"}; + escape("") + + "\\u003c\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e\\u003c\\u0063\\u0031\\u003e\\u0061\\u003c\\u002f\\u0063\\u0031\\u003e\\u003c\\u0063\\u0032\\u003e\\u003f\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0032\\u003e\\u003c\\u0063\\u0033\\u003e\\u003f\\u003f\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0033\\u003e\\u003c\\u0063\\u0034\\u003e\\u043c\\u0438\\u0440\\u003c\\u002f\\u0063\\u0034\\u003e\\u003c\\u0063\\u0035\\u003e\\u623f\\u95f4\\u003c\\u002f\\u0063\\u0035\\u003e\\u003c\\u002f\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e"}; + } + else if (TestCharset.WINDOWS1250.equals(charsetXmlResponseHeader)) { + expected = new String[] { + escape("") + + "\\u003c\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e\\u003c\\u0063\\u0031\\u003e\\u0061\\u003c\\u002f\\u0063\\u0031\\u003e\\u003c\\u0063\\u0032\\u003e\\u003f\\u003f\\u00e4\\u00a9\\u003c\\u002f\\u0063\\u0032\\u003e\\u003c\\u0063\\u0033\\u003e\\u003f\\u003f\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0033\\u003e\\u003c\\u0063\\u0034\\u003e\\u003f\\u003f\\u003f\\u003c\\u002f\\u0063\\u0034\\u003e\\u003c\\u0063\\u0035\\u003e\\u003f\\u003f\\u003c\\u002f\\u0063\\u0035\\u003e\\u003c\\u002f\\u0068\\u0074\\u006d\\u006c\\u0075\\u006e\\u0069\\u0074\\u003e"}; } } } diff --git a/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequestResponseXMLEncodingTest.java b/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequestResponseXMLEncodingTest.java index f0422e94e8..dce62cfe11 100644 --- a/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequestResponseXMLEncodingTest.java +++ b/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequestResponseXMLEncodingTest.java @@ -46,10 +46,10 @@ public static Collection data() throws Exception { final String[] xmlEncodingHeaders = {"", "utf8"}; final TestCharset[] charsetHtmlResponseHeaders = - new TestCharset[] {null, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.GB2312}; + new TestCharset[] {null, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.WINDOWS1250, TestCharset.GB2312}; final TestMimeType[] mimeTypeXmls = {TestMimeType.EMPTY, TestMimeType.XML, TestMimeType.PLAIN}; final TestCharset[] charsetXmlResponseHeaders = - new TestCharset[] {null, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.GB2312}; + new TestCharset[] {null, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.WINDOWS1250, TestCharset.GB2312}; final String[] boms = {null, BOM_UTF_8, BOM_UTF_16LE, BOM_UTF_16BE}; for (final Object xmlEncodingHeader : xmlEncodingHeaders) { @@ -139,6 +139,16 @@ private void responseText( + " \n" + " \n" + " \n" @@ -162,7 +172,7 @@ private void responseText( final String xml = "" + "" + "a" - + "\u00E4" + + "\u008A\u009A\u00E4\u00A9" + "\u0623\u0647\u0644\u0627\u064B" + "\u043C\u0438\u0440" + "\u623F\u95F4" @@ -170,40 +180,37 @@ private void responseText( String[] expected = getExpectedAlerts(); if (expected == null || expected.length == 0) { - expected = new String[] {"a", "�", "?????", "???", "??"}; + expected = new String[] {"\\u0061","\\u0160\\u0161\\u00e4\\u00a9", "\\u003f\\u003f\\u003f\\u003f\\u003f", "\\u003f\\u003f\\u003f", "\\u003f\\u003f"}; if (TestMimeType.PLAIN.equals(mimeTypeXml)) { expected = new String[] {"null"}; } else if (TestCharset.UTF8.equals(charsetXmlResponseHeader) || bom != null) { - expected = new String[] {"a", "ä", "أهلاً", "мир", "房间"}; + expected = new String[] {"\\u0061", "\\u008a\\u009a\\u00e4\\u00a9", "\\u0623\\u0647\\u0644\\u0627\\u064b", "\\u043c\\u0438\\u0440", "\\u623f\\u95f4"}; } else if (TestMimeType.EMPTY.equals(mimeTypeXml)) { - /* real FF - ignored for the moment + /* real FF - ignored for the moment */ if (getBrowserVersion().isFirefox() && !TestCharset.UTF8.equals(charsetXmlResponseHeader)) { expected = new String[] {"null"}; } - else */ + else /**/ if (TestCharset.GB2312.equals(charsetXmlResponseHeader)) { - expected = new String[] {"a", "?", "?????", "�ާڧ�", "����"}; + expected = new String[] {"\\u0061", "\\u003f\\u003f\\u003f\\u003f", "\\u003f\\u003f\\u003f\\u003f\\u003f", "\\ufffd\\u07a7\\u06a7\\ufffd", "\\ufffd\\ufffd\\ufffd\\ufffd"}; } - } - else if (TestMimeType.XML.equals(mimeTypeXml)) { - if (TestCharset.GB2312.equals(charsetXmlResponseHeader)) { - expected = new String[] {"a", "?", "?????", "мир", "房间"}; + else if (TestCharset.WINDOWS1250.equals(charsetXmlResponseHeader)) { + expected = new String[] {"\\u0061", "\\u003f\\u003f\\ufffd", "\\u003f\\u003f\\u003f\\u003f\\u003f", "\\u003f\\u003f\\u003f", "\\u003f\\u003f"}; } - else if (null == charsetXmlResponseHeader - || TestCharset.ISO88591.equals(charsetXmlResponseHeader)) { - expected = new String[] {"a", "ä", "?????", "???", "??"}; + else if (null == charsetXmlResponseHeader || TestCharset.ISO88591.equals(charsetXmlResponseHeader)) { + expected = new String[] {"\\u0061", "\\ufffd\\ufffd\\ufffd", "\\u003f\\u003f\\u003f\\u003f\\u003f", "\\u003f\\u003f\\u003f", "\\u003f\\u003f"}; } } - else { + else if (TestMimeType.XML.equals(mimeTypeXml)) { if (TestCharset.GB2312.equals(charsetXmlResponseHeader)) { - expected = new String[] {"a", "?", "?????", "мир", "房间"}; + expected = new String[] {"\\u0061", "\\u003f\\u003f\\u003f\\u003f", "\\u003f\\u003f\\u003f\\u003f\\u003f", "\\u043c\\u0438\\u0440", "\\u623f\\u95f4"}; } - else if (TestCharset.ISO88591.equals(charsetXmlResponseHeader)) { - expected = new String[] {"a", "ä", "?????", "???", "??"}; + else if (TestCharset.WINDOWS1250.equals(charsetXmlResponseHeader)) { + expected = new String[] {"\\u0061", "\\u003f\\u003f\\u00e4\\u00a9", "\\u003f\\u003f\\u003f\\u003f\\u003f","\\u003f\\u003f\\u003f", "\\u003f\\u003f"}; } } }