Skip to content

Commit

Permalink
fix NPE when defining a javascript constructor alias for a non existi…
Browse files Browse the repository at this point in the history
…ng constructor
  • Loading branch information
rbri committed Feb 9, 2024
1 parent fade164 commit a76bd96
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

<body>
<release version="3.11.0" date="February xx, 2024" description="Chrome/Edge 121, Firefox 122, many Neko improvements, Bugfixes">
<action type="fix" dev="rbri">
Fix NPE when defining a javascript constructor alias for a non existing constructor.
</action>
<action type="fix" dev="rbri">
Method org.htmlunit.javascript.host.css.CSSStyleSheet.validateSelectors(SelectorList, int, DomNode) does not
forward the SelectorList to the implementation (regression from version 3.7.0)
forward the SelectorList to the implementation (regression from version 3.7.0).
</action>
<action type="update" dev="rbri">
Upgrade commons-codec to 1.16.1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ void setJSConstructor(final String name, final Member jsConstructor) {

void setJSConstructorAlias(final String alias) {
if (jsConstructor_ == null) {
throw new IllegalStateException("Can not define an constructor alias for "
+ jsConstructor_.getValue().getDeclaringClass().getName()
+ " because there is no JsxConstructor defined");
throw new IllegalStateException("Can not define the constructor alias '"
+ alias + "' for scriptable class -'"
+ hostClass_.getName()
+ "' because there is no JsxConstructor defined");
}
jsConstructorAlias_ = alias;
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/htmlunit/html/HtmlPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.htmlunit.junit.BrowserRunner.TestedBrowser.IE;
import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -34,6 +35,7 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.SerializationUtils;
import org.htmlunit.CollectingAlertHandler;
Expand Down Expand Up @@ -1039,6 +1041,20 @@ public void asXml() throws Exception {
assertEquals(htmlContent, xml.replaceAll("\\s", ""));
}

/**
* @exception Exception If the test fails
*/
@Test
public void asXml1() throws Exception {
final String htmlContent = FileUtils.readFileToString(new File("D:\\test.resp"), StandardCharsets.UTF_8);

getWebClient().getOptions().setJavaScriptEnabled(false);

final HtmlPage page = loadPage(htmlContent);
String xml = page.asXml();
System.out.println(xml);
}

/**
* Tests that the generated XML is valid as HTML code too.
* @exception Exception If the test fails
Expand Down

0 comments on commit a76bd96

Please sign in to comment.