Author: ivaynberg
Date: Thu Sep 22 07:04:32 2011
New Revision: 1173971
URL: http://svn.apache.org/viewvc?rev=1173971&view=rev
Log:
WICKET-4072
Modified:
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/Url.java
wicket/trunk/wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java
Modified:
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/Url.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/Url.java?rev=1173971&r1=1173970&r2=1173971&view=diff
==============================================================================
---
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/Url.java
(original)
+++
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/Url.java
Thu Sep 22 07:04:32 2011
@@ -106,7 +106,7 @@ public final class Url implements Serial
* Parses the given URL string.
*
* @param url
- * absolute or relative url with query string
+ * absolute or relative url with query string
* @return Url object
*/
public static Url parse(final String url)
@@ -118,7 +118,7 @@ public final class Url implements Serial
* Parses the given URL string.
*
* @param url
- * absolute or relative url with query string
+ * absolute or relative url with query string
* @param charset
* @return Url object
*/
@@ -147,7 +147,7 @@ public final class Url implements Serial
absoluteUrl = url.substring(0, queryAt);
queryString = url.substring(queryAt + 1);
}
-
+
// get absolute / relative part of url
String relativeUrl;
@@ -157,12 +157,12 @@ public final class Url implements Serial
if (protocolAt != -1)
{
result.protocol = absoluteUrl.substring(0,
protocolAt).toLowerCase(Locale.US);
-
+
final String afterProto =
absoluteUrl.substring(protocolAt + 3);
final String hostAndPort;
final int relativeAt = afterProto.indexOf('/');
-
+
if (relativeAt == -1)
{
relativeUrl = "";
@@ -236,7 +236,7 @@ public final class Url implements Serial
* get default port number for protocol
*
* @param protocol
- * name of protocol
+ * name of protocol
* @return default port for protocol or <code>null</code> if unknown
*/
private static Integer getDefaultPortForProtocol(String protocol)
@@ -311,7 +311,7 @@ public final class Url implements Serial
*/
public Url(final List<String> segments, final Charset charset)
{
- this(segments, Collections.<QueryParameter>emptyList(),
charset);
+ this(segments, Collections.<QueryParameter> emptyList(),
charset);
}
/**
@@ -592,8 +592,8 @@ public final class Url implements Serial
}
/**
- * render full representation of url (including protocol, host and
port)
- * into string representation
+ * render full representation of url (including protocol, host and
port) into string
+ * representation
*/
public String toAbsoluteString()
{
@@ -601,8 +601,8 @@ public final class Url implements Serial
}
/**
- * render full representation of url (including protocol, host and
port)
- * into string representation
+ * render full representation of url (including protocol, host and
port) into string
+ * representation
*
* @param charset
*
@@ -613,13 +613,13 @@ public final class Url implements Serial
StringBuilder result = new StringBuilder();
// output scheme://host:port if specified
- if(protocol != null && Strings.isEmpty(host) == false)
+ if (protocol != null && Strings.isEmpty(host) == false)
{
result.append(protocol);
result.append("://");
result.append(host);
-
- if(port != null &&
port.equals(getDefaultPortForProtocol(protocol)) == false)
+
+ if (port != null &&
port.equals(getDefaultPortForProtocol(protocol)) == false)
{
result.append(':');
result.append(port);
@@ -627,7 +627,7 @@ public final class Url implements Serial
}
// append relative part
result.append(this.toString());
-
+
// return url string
return result.toString();
}
@@ -880,9 +880,11 @@ public final class Url implements Serial
*/
public void resolveRelative(final Url relative)
{
- // strip the first non-folder segment
- getSegments().remove(getSegments().size() - 1);
-
+ if (getSegments().size() > 0)
+ {
+ // strip the first non-folder segment
+ getSegments().remove(getSegments().size() - 1);
+ }
// remove all './' (current folder) from the relative url
if (!relative.getSegments().isEmpty() &&
".".equals(relative.getSegments().get(0)))
{
@@ -963,13 +965,13 @@ public final class Url implements Serial
{
this.host = host;
}
-
+
/**
- * return path for current url in given encoding
+ * return path for current url in given encoding
*
* @param charset
- * character set for encoding
- *
+ * character set for encoding
+ *
* @return path string
*/
public String getPath(Charset charset)
@@ -992,7 +994,7 @@ public final class Url implements Serial
}
/**
- * return path for current url in original encoding
+ * return path for current url in original encoding
*
* @return path string
*/
@@ -1005,7 +1007,7 @@ public final class Url implements Serial
* return query string part of url in given encoding
*
* @param charset
- * character set for encoding
+ * character set for encoding
*
* @return query string
*/
Modified:
wicket/trunk/wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java?rev=1173971&r1=1173970&r2=1173971&view=diff
==============================================================================
---
wicket/trunk/wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java
(original)
+++
wicket/trunk/wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java
Thu Sep 22 07:04:32 2011
@@ -366,6 +366,30 @@ public class UrlTest extends TestCase
}
/**
+ * Tries to resolve a relative url against a base that has no segments
+ */
+ public void testResolveRelative_NoSegmentsInBase()
+ {
+ Url relative = Url.parse("?a=b");
+ Url baseUrl = Url.parse("?foo=bar");
+ baseUrl.resolveRelative(relative);
+
+ assertEquals("?a=b", baseUrl.toString());
+ }
+
+ /**
+ * Tries to resolve a relative url against a base that has no segments
+ */
+ public void testResolveRelative_NoSegmentsInBase2()
+ {
+ Url relative = Url.parse("bar/baz?a=b");
+ Url baseUrl = Url.parse("?foo=bar");
+ baseUrl.resolveRelative(relative);
+
+ assertEquals("bar/baz?a=b", baseUrl.toString());
+ }
+
+ /**
* Tests that the default charset is UTF-8
*/
public void testCharset1()