Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

<body>
<release version="5.8.0" date="xxxx xx, 2026" description="Bugfixes">
<action type="fix" dev="Vidya m">
XMLHttpRequest: asynchronous requests to file: urls no longer load the file if
WebClientOptions.isFileProtocolForXMLHttpRequestsAllowed() is false.
</action>
<action type="fix" dev="rbri" issue="#722">
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
23 changes: 23 additions & 0 deletions src/test/resources/testfiles/localxmlhttprequest/index_async.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<html>

Check warning on line 1 in src/test/resources/testfiles/localxmlhttprequest/index_async.html

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Insert a <!DOCTYPE> declaration to before this <html> tag.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit&issues=AaGhBvER0jD5b517v0OX&open=AaGhBvER0jD5b517v0OX&pullRequest=1185

Check warning on line 1 in src/test/resources/testfiles/localxmlhttprequest/index_async.html

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add "lang" and/or "xml:lang" attributes to the "<html>" or "<body>" element

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit&issues=AaGhBvER0jD5b517v0OZ&open=AaGhBvER0jD5b517v0OZ&pullRequest=1185
<head><script>

Check warning on line 2 in src/test/resources/testfiles/localxmlhttprequest/index_async.html

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a <title> tag to this page.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit&issues=AaGhBvER0jD5b517v0OY&open=AaGhBvER0jD5b517v0OY&pullRequest=1185
function log(msg) { window.document.title += msg + '\u00a7'; }
function test() {
try {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(event) {
log(event.type);
log(xhr.readyState);
log(xhr.responseText.length);
};
xhr.onerror = function(event) {
log(event.type);
};
xhr.open('GET', 'index_async.html', true);
xhr.send('');
} catch (exception) {
log(exception.name);
}
}
</script></head>
<body onload='test()'>
</body></html>
Loading