Skip to content

Commit

Permalink
Fix SvgScript NPE when script engine not available. (#155)
Browse files Browse the repository at this point in the history
* Fix SvgScript NPE when script engine not available.
* Update contributors list.
* Update authors.
Co-authored-by: ronnyshapiro <[email protected]>
  • Loading branch information
rbri committed Apr 14, 2020
1 parent e8903bd commit d247660
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,9 @@
<contributor>
<name>Alex Gorbatovsky</name>
</contributor>
<contributor>
<name>Ronny Shapiro</name>
</contributor>
</contributors>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
*
* @author Ahmed Ashour
* @author Ronald Brill
* @author Ronny Shapiro
*/
public final class ScriptElementSupport {

Expand Down Expand Up @@ -77,6 +78,13 @@ public static void onAllChildrenAddedToPage(final DomElement element, final bool
LOG.debug("Script node added: " + element.asXml());
}

if (!element.getPage().getWebClient().isJavaScriptEngineEnabled()) {
if (LOG.isDebugEnabled()) {
LOG.debug("SvgScript found but not executed because javascript engine is disabled");
}
return;
}

final PostponedAction action = new PostponedAction(element.getPage(), "Execution of script " + element) {
@Override
public void execute() {
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/gargoylesoftware/htmlunit/WebClient8Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Tests for {@link WebClient} running with js disabled.
*
* @author Ronald Brill
* @author Ronny Shapiro
*/
@RunWith(BrowserRunner.class)
public class WebClient8Test extends SimpleWebTestCase {
Expand Down Expand Up @@ -287,4 +288,25 @@ public void object() throws Exception {
webClient.getPage(URL_FIRST);
}
}

/**
* @throws Exception if something goes wrong
*/
@Test
public void svgScript() throws Exception {
final String html = "<html>\n"
+ "<head>\n"
+ " <title>foo</title>\n"
+ "</head>\n"
+ "<body>\n"
+ " <svg xmlns='http://www.w3.org/2000/svg' version='1.1'>\n"
+ " <script id='myId'></script>\n"
+ " </svg>\n"
+ "</body></html>";

try (WebClient webClient = new WebClient(getBrowserVersion(), false, null, -1)) {
final HtmlPage page = loadPage(webClient, html, null, URL_FIRST);
assertEquals(page.getBody().getChildElementCount(), 1);
}
}
}

0 comments on commit d247660

Please sign in to comment.