From 925d36c782676955880304cc6a5ac068c7ecad33 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Tue, 11 Dec 2012 08:23:42 +0100 Subject: [PATCH] Fix encoding/decoding of dashboard ids (one more time) The encoding of the dashboard id on client side is done by URL.encode(...). This method is not encoding the URL component delimiter characters (e.g. '/'). This means if the dashboard ref contains '/' it is not encoded and as result the RestApiServlet on the server interprets '/' as seperator for the rest collections and the loading of the dashboard fails. When the dashboard URL is encoded on the server side by Url.encode(...) space is encoded as '+'. Decoding this on the client side in Dispatcher with URL.decodePathSegment(...) will not decode '+' to space. Instead we need to use URL.decodeQueryString(...) which makes sure to decode '+' to space. The encoding on client side should be consistent with the decoding, this is why URL.encodeQueryString(...) is used to encode the dashboard id. With the new encoding/decoding loading dashboards that contain '/' in their ref or path succeeds as well as loading dashboards that have spaces in their path. Change-Id: I4c17bd6caf517faf68b71d39656229af4eb87e99 Signed-off-by: Edwin Kempin --- .../src/main/java/com/google/gerrit/client/Dispatcher.java | 4 ++-- .../com/google/gerrit/client/dashboards/DashboardList.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Dispatcher.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Dispatcher.java index d7db9acf2c..e72e127619 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Dispatcher.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Dispatcher.java @@ -434,8 +434,8 @@ public class Dispatcher { } c = dashboardId.indexOf(":"); if (0 <= c) { - final String ref = URL.decode(dashboardId.substring(0, c)); - final String path = URL.decode(dashboardId.substring(c + 1)); + final String ref = URL.decodeQueryString(dashboardId.substring(0, c)); + final String path = URL.decodeQueryString(dashboardId.substring(c + 1)); DashboardList.get(new Project.NameKey(project), ref + ":" + path, cb); return; } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardList.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardList.java index f4da5faddf..2fb4c17314 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardList.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardList.java @@ -50,11 +50,11 @@ public class DashboardList extends NativeList { private static String encodeDashboardId(String dashboardId) { int c = dashboardId.indexOf(":"); if (0 <= c) { - final String ref = URL.encode(dashboardId.substring(0, c)); - final String path = URL.encode(dashboardId.substring(c + 1)); + final String ref = URL.encodeQueryString(dashboardId.substring(0, c)); + final String path = URL.encodeQueryString(dashboardId.substring(c + 1)); return ref + ":" + path; } else { - return URL.encode(dashboardId); + return URL.encodeQueryString(dashboardId); } }