Skip to content

Commit cb087e1

Browse files
committed
document last fix and add webdriver tests to prove the changes with real browsers
1 parent 5f73df3 commit cb087e1

3 files changed

Lines changed: 89 additions & 2 deletions

File tree

src/changes/changes.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
<body>
1010
<release version="5.1.0" date="June xx, 2026" description="Bugfixes">
11+
<action type="fix" dev="Lai Quang Duong">
12+
Fix Location.setHash() to update the page's WebRequest URL when the hash changes,
13+
ensuring page.getUrl() reflects the current hash.
14+
</action>
15+
<action type="fix" dev="Lai Quang Duong">
16+
Fix WebClient.makeWebResponseForAboutUrl() to properly handle about:blank with hash fragments
17+
(e.g., about:blank#foo) instead of throwing MalformedURLException.
18+
</action>
1119
<action type="fix" dev="RhinoTeam">
1220
core-js: Array spread throws TypeError on non-iterable, null, or undefined targets.
1321
</action>

src/test/java/org/htmlunit/javascript/host/Location2Test.java

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,9 +1489,9 @@ public void reloadGetHashChanged() throws Exception {
14891489
@Test
14901490
@Alerts(DEFAULT = {"1", "2", "3", "a.html?urlParam=urlVal",
14911491
"4", "http://§§URL§§", "http://§§URL§§/second/a.html?urlParam=urlVal", "§§URL§§"},
1492-
FF = {"1", "2", "2", "a.html?urlParam=urlVal",
1492+
FF = {"1", "2", "3", "a.html?urlParam=urlVal",
14931493
"4", "http://§§URL§§", "http://§§URL§§/", "§§URL§§"},
1494-
FF_ESR = {"1", "2", "2", "a.html?urlParam=urlVal",
1494+
FF_ESR = {"1", "2", "3", "a.html?urlParam=urlVal",
14951495
"4", "http://§§URL§§", "http://§§URL§§/", "§§URL§§"})
14961496
public void reloadPost() throws Exception {
14971497
final String form = DOCTYPE_HTML
@@ -1691,4 +1691,82 @@ public void ownPropertyDescriptor() throws Exception {
16911691
expandExpectedAlertsVariables(URL_FIRST);
16921692
loadPageVerifyTitle2(html);
16931693
}
1694+
1695+
/**
1696+
* Verifies that modifying <tt>window.location.hash</tt> works, but that it doesn't
1697+
* force the page to reload from the server. This is very important for the Dojo
1698+
* unit tests, which will keep reloading themselves if the page gets reloaded.
1699+
*
1700+
* @throws Exception if the test fails
1701+
*/
1702+
@Test
1703+
@Alerts({"", "#b"})
1704+
public void setHash() throws Exception {
1705+
final String html = DOCTYPE_HTML
1706+
+ "<html><head>\n"
1707+
+ "<script>\n"
1708+
+ LOG_TITLE_FUNCTION
1709+
+ "</script>\n"
1710+
+ "</head>\n"
1711+
+ "<body>\n"
1712+
+ "<a id='a' onclick='log(location.hash);location.hash=\"b\";log(location.hash);'>go</a>\n"
1713+
+ "<h2 id='b'>...</h2>\n"
1714+
+ "</body>\n"
1715+
+ "</html>";
1716+
1717+
final WebDriver driver = loadPage2(html);
1718+
driver.findElement(By.id("a")).click();
1719+
1720+
verifyTitle2(driver, getExpectedAlerts());
1721+
1722+
assertEquals(URL_FIRST, getMockWebConnection().getLastWebRequest().getUrl());
1723+
assertEquals(1, getMockWebConnection().getRequestCount());
1724+
}
1725+
1726+
/**
1727+
* @throws Exception if the test fails
1728+
*/
1729+
@Test
1730+
@Alerts("§§URL§§#newHash")
1731+
public void setHashUpdatesPageUrl() throws Exception {
1732+
final String html = DOCTYPE_HTML
1733+
+ "<html><head>\n"
1734+
+ "<script>\n"
1735+
+ LOG_TITLE_FUNCTION
1736+
+ "</script>\n"
1737+
+ "</head>\n"
1738+
+ "<body>\n"
1739+
+ "<a id='a' onclick='location.hash=\"newHash\"'>go</a>'>go</a>\n"
1740+
+ "</body>\n"
1741+
+ "</html>";
1742+
1743+
final WebDriver driver = loadPage2(html);
1744+
driver.findElement(By.id("a")).click();
1745+
1746+
expandExpectedAlertsVariables(URL_FIRST);
1747+
1748+
assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
1749+
assertEquals(1, getMockWebConnection().getRequestCount());
1750+
}
1751+
1752+
/**
1753+
* @throws Exception if the test fails
1754+
*/
1755+
@Test
1756+
@Alerts({"about:blank", "about:blank#foo", "about:blank#foo"})
1757+
public void setHashAboutBlank() throws Exception {
1758+
WebDriver driver = getWebDriver();
1759+
driver.get("about:blank");
1760+
1761+
assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
1762+
assertEquals(0, getMockWebConnection().getRequestCount());
1763+
1764+
((JavascriptExecutor) driver).executeScript("location.hash = 'foo'");
1765+
assertEquals(getExpectedAlerts()[1], driver.getCurrentUrl());
1766+
assertEquals(0, getMockWebConnection().getRequestCount());
1767+
1768+
driver.navigate().refresh();
1769+
assertEquals(getExpectedAlerts()[2], driver.getCurrentUrl());
1770+
assertEquals(0, getMockWebConnection().getRequestCount());
1771+
}
16941772
}

src/test/java/org/htmlunit/javascript/host/LocationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ public void setHash() throws Exception {
295295

296296
// Verify that we didn't reload the page.
297297
assertTrue(page == page2);
298+
assertEquals(URL_FIRST + "#b", conn.getLastWebRequest().getUrl());
298299
assertEquals(1, conn.getRequestCount());
299300
}
300301

0 commit comments

Comments
 (0)