Fixes a History bug where urlencoded history tokens lose their
encoding when they are delivered to HistoryListeners. A summary of
changes:

(1) Removed several calls to decodeURIComponent on location.hash
    which is already url unescaped by design.
(2) Added a test to verify the fix.
(3) Cleaned up an unused javascript var in history.html.

Reviewed by: jgw
Fixes: 572



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@402 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/core/public/history.html b/user/src/com/google/gwt/core/public/history.html
index 3bd14c5..cefb9ac 100644
--- a/user/src/com/google/gwt/core/public/history.html
+++ b/user/src/com/google/gwt/core/public/history.html
@@ -4,8 +4,8 @@
 function hst() {
   var search = location.search;
   var historyToken = '';
-  if (location.search.length > 0)
-    historyToken = decodeURIComponent(location.search.substring(1));
+  if (search.length > 0)
+    historyToken = search.substring(1);
 
   document.getElementById('__historyToken').value = historyToken;
   if (parent.__onHistoryChanged)
diff --git a/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java b/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java
index 307097b..95e399a 100644
--- a/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java
+++ b/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java
@@ -34,7 +34,7 @@
     // Get the initial token from the url's hash component.
     var hash = $wnd.location.hash;
     if (hash.length > 0)
-      $wnd.__historyToken = decodeURIComponent(hash.substring(1));
+      $wnd.__historyToken = hash.substring(1);
     else
       $wnd.__historyToken = '';
 
@@ -73,7 +73,7 @@
     var urlChecker = function() {
       var hash = $wnd.location.hash;
       if (hash.length > 0) {
-        var token = decodeURIComponent(hash.substring(1));
+        var token = hash.substring(1);
         if ($wnd.__historyToken && (token != $wnd.__historyToken))
           $wnd.location.reload();
       }
diff --git a/user/src/com/google/gwt/user/client/impl/HistoryImplSafari.java b/user/src/com/google/gwt/user/client/impl/HistoryImplSafari.java
index e777c67..5bed029 100644
--- a/user/src/com/google/gwt/user/client/impl/HistoryImplSafari.java
+++ b/user/src/com/google/gwt/user/client/impl/HistoryImplSafari.java
@@ -33,7 +33,7 @@
     // Get the initial token from the url's hash component.
     var hash = $wnd.location.hash;
     if (hash.length > 0)
-      $wnd.__historyToken = decodeURIComponent(hash.substring(1));
+      $wnd.__historyToken = hash.substring(1);
     else
       $wnd.__historyToken = '';
 
diff --git a/user/src/com/google/gwt/user/client/impl/HistoryImplStandard.java b/user/src/com/google/gwt/user/client/impl/HistoryImplStandard.java
index 10c66f0..dc1cc12 100644
--- a/user/src/com/google/gwt/user/client/impl/HistoryImplStandard.java
+++ b/user/src/com/google/gwt/user/client/impl/HistoryImplStandard.java
@@ -30,13 +30,13 @@
     // Get the initial token from the url's hash component.
     var hash = $wnd.location.hash;
     if (hash.length > 0)
-      $wnd.__historyToken = decodeURIComponent(hash.substring(1));
+      $wnd.__historyToken = hash.substring(1);
 
     // Create the timer that checks the browser's url hash every 1/4 s.
     $wnd.__checkHistory = function() {
       var token = '', hash = $wnd.location.hash;
       if (hash.length > 0)
-        token = decodeURIComponent(hash.substring(1));
+        token = hash.substring(1);
 
       if (token != $wnd.__historyToken) {
         $wnd.__historyToken = token;
diff --git a/user/test/com/google/gwt/user/client/ui/HistoryTest.java b/user/test/com/google/gwt/user/client/ui/HistoryTest.java
index 7ec1cbe..47b7894 100644
--- a/user/test/com/google/gwt/user/client/ui/HistoryTest.java
+++ b/user/test/com/google/gwt/user/client/ui/HistoryTest.java
@@ -10,6 +10,19 @@
   public String getModuleName() {
     return "com.google.gwt.user.User";
   }
+  
+  /* Tests against issue #572: Double unescaping of history tokens. */
+  public void testTokenEscaping() {
+	final String escToken = "%24%24%24";
+	delayTestFinish(5000);
+	History.addHistoryListener(new HistoryListener() {
+	  public void onHistoryChanged(String token) {
+		assertEquals(escToken,token);
+		finishTest();
+	  }
+	});
+	History.newItem(escToken);
+  }
 
   /*
    * Ensure that non-url-safe strings (such as those containing spaces) are
@@ -51,5 +64,5 @@
     });
 
     History.newItem("foo bar");
-  }
+  }  
 }