Author: mgrigorov
Date: Sat Sep 25 17:09:42 2010
New Revision: 1001273

URL: http://svn.apache.org/viewvc?rev=1001273&view=rev
Log:
WICKET-3076 UrlUtils.isRelative returns false if URL parameter contains an 
absolute URL

Use regular expression to check whether the passed url string starts with 
'scheme://'


Added:
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/string/UrlUtilsTest.java
   (with props)
Modified:
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/UrlUtils.java

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/UrlUtils.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/UrlUtils.java?rev=1001273&r1=1001272&r2=1001273&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/UrlUtils.java 
(original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/UrlUtils.java 
Sat Sep 25 17:09:42 2010
@@ -39,9 +39,10 @@ public class UrlUtils
         * @param url
         * @return <code>true</code> if url is relative, <code>false</code> 
otherwise
         */
-       public static boolean isRelative(String url)
+       public static boolean isRelative(final String url)
        {
-               if ((url != null) && (url.startsWith("/") == false) && 
(url.indexOf("://") < 0) &&
+               // the regex means "doesn't start with 'scheme://'"
+               if ((url != null) && (url.startsWith("/") == false) && 
(!url.matches("^\\w+\\:\\/\\/.*")) &&
                        !(url.startsWith("#")))
                {
                        return true;

Added: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/string/UrlUtilsTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/string/UrlUtilsTest.java?rev=1001273&view=auto
==============================================================================
--- 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/string/UrlUtilsTest.java
 (added)
+++ 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/string/UrlUtilsTest.java
 Sat Sep 25 17:09:42 2010
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.string;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Tests for {...@link UrlUtils}
+ */
+public class UrlUtilsTest
+{
+
+       @Test
+       public void isRelative()
+       {
+               
assertTrue(UrlUtils.isRelative("./mypage?return=http://example.com";));
+               assertTrue(UrlUtils.isRelative("./path/path2?param1=value1"));
+               assertFalse(UrlUtils.isRelative("http://example.com";));
+               assertFalse(UrlUtils.isRelative("https://example.com";));
+               assertFalse(UrlUtils.isRelative("ftp://example.com";));
+       }
+}

Propchange: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/util/string/UrlUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to