mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-05 04:38:10 +08:00
ControllerUtils#getLocationWithoutParams does not cut parameters #PL-2644
This commit is contained in:
parent
6a3250bb9d
commit
0ebdd35f0d
@ -11,6 +11,8 @@ import com.haulmont.cuba.security.app.LoginService;
|
||||
import com.haulmont.cuba.security.global.UserSession;
|
||||
import com.haulmont.cuba.web.App;
|
||||
import com.haulmont.cuba.web.AppUI;
|
||||
import com.vaadin.server.VaadinSession;
|
||||
import com.vaadin.ui.UI;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@ -30,10 +32,14 @@ public abstract class ControllerUtils {
|
||||
|
||||
public static String getLocationWithoutParams() {
|
||||
URI location = AppUI.getCurrent().getPage().getLocation();
|
||||
return getLocationWithoutParams(location);
|
||||
}
|
||||
|
||||
public static String getLocationWithoutParams(URI location) {
|
||||
try {
|
||||
StringBuilder baseUrl = new StringBuilder(location.toURL().toExternalForm());
|
||||
if (location.getQuery() != null) {
|
||||
baseUrl.delete(baseUrl.indexOf(location.getQuery()) - 1, baseUrl.length());
|
||||
baseUrl.delete(baseUrl.indexOf("?" + location.getQuery()), baseUrl.length());
|
||||
}
|
||||
return baseUrl.toString();
|
||||
} catch (MalformedURLException e) {
|
||||
@ -103,4 +109,4 @@ public abstract class ControllerUtils {
|
||||
return userSession;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Haulmont. All rights reserved.
|
||||
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.web.test;
|
||||
|
||||
import com.haulmont.cuba.web.controllers.ControllerUtils;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author artamonov
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ControllerUtilsTest extends TestCase {
|
||||
public void testGetLocationWithoutParams() throws Exception {
|
||||
URI localUrl = new URI("http://localhost:8080/app?a");
|
||||
assertEquals(ControllerUtils.getLocationWithoutParams(localUrl), "http://localhost:8080/app");
|
||||
|
||||
URI externalUrl = new URI("http://ya.ru/app/sample/?param=value");
|
||||
assertEquals(ControllerUtils.getLocationWithoutParams(externalUrl), "http://ya.ru/app/sample/");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user