diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9ad62f4e274..a65f398e5a4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -8,6 +8,10 @@
+
+ XMLHttpRequest: asynchronous requests to file: urls no longer load the file if
+ WebClientOptions.isFileProtocolForXMLHttpRequestsAllowed() is false.
+
KeyboardEvent: key, code and location are now correct for special keys (arrows, navigation,
function keys, numpad, modifiers, ...) and the code is correct for digits, space and punctuation.
diff --git a/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java b/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java
index b28b869d783..040a8f51154 100644
--- a/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java
+++ b/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java
@@ -998,13 +998,13 @@ void doSend() {
fireJavascriptEvent(Event.TYPE_READY_STATE_CHANGE);
fireJavascriptEvent(Event.TYPE_ERROR);
fireJavascriptEvent(Event.TYPE_LOAD_END);
+ return;
}
- else {
- throw JavaScriptEngine.asJavaScriptException(
- window,
- "Not allowed to load local resource: " + webRequest_.getUrl(),
- DOMException.NETWORK_ERR);
- }
+
+ throw JavaScriptEngine.asJavaScriptException(
+ window,
+ "Not allowed to load local resource: " + webRequest_.getUrl(),
+ DOMException.NETWORK_ERR);
}
final BrowserVersion browserVersion = getBrowserVersion();
diff --git a/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequest4Test.java b/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequest4Test.java
index 2f972de9cad..6a1d570ebd6 100644
--- a/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequest4Test.java
+++ b/src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequest4Test.java
@@ -217,4 +217,21 @@ public void sendLocalSubFileAllowed() throws Exception {
assertEquals(0, client.waitForBackgroundJavaScriptStartingBefore(1000));
assertEquals(getExpectedAlerts()[0], page.getTitleText());
}
+
+ /**
+ * @throws Exception if the test fails
+ */
+ @Test
+ @Alerts("readystatechange§1§0§readystatechange§4§0§error§")
+ public void sendLocalFileAsyncNotAllowed() throws Exception {
+ final URL fileURL = getClass().getClassLoader().getResource("testfiles/localxmlhttprequest/index_async.html");
+ final File file = new File(fileURL.toURI());
+ assertTrue("File '" + file.getAbsolutePath() + "' does not exist", file.exists());
+
+ final WebClient client = getWebClient();
+ final HtmlPage page = client.getPage(fileURL);
+
+ assertEquals(0, client.waitForBackgroundJavaScriptStartingBefore(1000));
+ assertEquals(getExpectedAlerts()[0], page.getTitleText());
+ }
}
diff --git a/src/test/resources/testfiles/localxmlhttprequest/index_async.html b/src/test/resources/testfiles/localxmlhttprequest/index_async.html
new file mode 100644
index 00000000000..50490628d8a
--- /dev/null
+++ b/src/test/resources/testfiles/localxmlhttprequest/index_async.html
@@ -0,0 +1,23 @@
+
+
+
+