Skip to content

Commit

Permalink
test IANA encoding name not supported by java
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Apr 27, 2024
1 parent fcd228d commit 4f6ebf5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test/java/org/htmlunit/cyberneko/GeneralTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@
package org.htmlunit.cyberneko;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;

import org.htmlunit.cyberneko.html.dom.HTMLDocumentImpl;
import org.htmlunit.cyberneko.parsers.DOMParser;
import org.htmlunit.cyberneko.xerces.xni.QName;
import org.htmlunit.cyberneko.xerces.xni.parser.XMLDocumentFilter;
import org.htmlunit.cyberneko.xerces.xni.parser.XMLInputSource;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.xml.sax.InputSource;

Expand Down Expand Up @@ -187,4 +191,36 @@ public void parseInputSourceResolvesToReplacement() throws Exception {
+ ")html";
assertEquals(expected.trim(), out.toString().trim());
}

@Test
public void parseInputSourceIANAEncoding() throws Exception {
final DOMParser parser = new DOMParser(HTMLDocumentImpl.class);

final StringWriter out = new StringWriter();
final XMLDocumentFilter[] filters = {new Writer(out)};
parser.setProperty("http://cyberneko.org/html/properties/filters", filters);

final String html = "some text ©€π√";
final InputSource in = new InputSource(new ByteArrayInputStream(html.getBytes(Charset.forName("x-MacRoman"))));
in.setEncoding("macintosh");
parser.parse(in);

try {
// not supported by the jdk
Charset.forName("macintosh");
Assertions.fail("UnsupportedCharsetException expected");
}
catch (UnsupportedCharsetException e) {
// expected
};

final String expected = "(HTML" + NL
+ "(head" + NL
+ ")head" + NL
+ "(body" + NL
+ "\"some text ©€π√" + NL
+ ")body" + NL
+ ")html";
assertEquals(expected.trim(), out.toString().trim());
}
}

0 comments on commit 4f6ebf5

Please sign in to comment.