From d97cfbc9a1409582bbe4456f08f648921b7e3300 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Fri, 2 Aug 2013 10:20:40 +0300 Subject: Refine handling of null and empty URI fragments (#12207) Change-Id: Ie133694b010a586c6336e9b04be7bcd94d2525e9 --- .../src/com/vaadin/client/ui/ui/UIConnector.java | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 45b0a7ab9d..c6d2e1436b 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -40,6 +40,7 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.History; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.Window.Location; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.google.web.bindery.event.shared.HandlerRegistration; @@ -352,14 +353,30 @@ public class UIConnector extends AbstractSingleComponentContainerConnector if (uidl.hasAttribute(UIConstants.LOCATION_VARIABLE)) { String location = uidl .getStringAttribute(UIConstants.LOCATION_VARIABLE); + String newFragment; + int fragmentIndex = location.indexOf('#'); if (fragmentIndex >= 0) { // Decode fragment to avoid double encoding (#10769) - getWidget().currentFragment = URL.decodePathSegment(location + newFragment = URL.decodePathSegment(location .substring(fragmentIndex + 1)); + + if (newFragment.isEmpty() + && Location.getHref().indexOf('#') == -1) { + // Ensure there is a trailing # even though History and + // Location.getHash() treat null and "" the same way. + Location.assign(Location.getHref() + "#"); + } + } else { + // No fragment in server-side location, but can't completely + // remove the browser fragment since that would reload the page + newFragment = ""; } - if (!getWidget().currentFragment.equals(History.getToken())) { - History.newItem(getWidget().currentFragment, true); + + getWidget().currentFragment = newFragment; + + if (!newFragment.equals(History.getToken())) { + History.newItem(newFragment, true); } } -- cgit v1.2.3