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 --- server/src/com/vaadin/server/Page.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index 3656309be5..037d8e8352 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -552,10 +552,11 @@ public class Page implements Serializable { * The fragment is the optional last component of a URI, prefixed with a * hash sign ("#"). *

- * Passing null as newFragment clears the fragment - * (no "#" in the URI); passing an empty string sets an empty fragment (a - * trailing "#" in the URI.) This is consistent with the semantics of - * {@link java.net.URI}. + * Passing an empty string as newFragment sets an empty + * fragment (a trailing "#" in the URI.) Passing null if there + * is already a non-null fragment will leave a trailing # in the URI since + * removing it would cause the browser to reload the page. This is not fully + * consistent with the semantics of {@link java.net.URI}. * * @param newUriFragment * The new fragment. @@ -570,6 +571,11 @@ public class Page implements Serializable { */ public void setUriFragment(String newUriFragment, boolean fireEvents) { String oldUriFragment = location.getFragment(); + if (newUriFragment == null && getUriFragment() != null) { + // Can't completely remove the fragment once it has been set, will + // instead set it to the empty string + newUriFragment = ""; + } if (newUriFragment == oldUriFragment || (newUriFragment != null && newUriFragment .equals(oldUriFragment))) { -- cgit v1.2.3