You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2008/12/20 09:24:05 UTC
svn commit: r728249 - in /wicket/trunk/wicket/src:
main/java/org/apache/wicket/validation/validator/UrlValidator.java
test/java/org/apache/wicket/validation/validator/UrlValidatorTest.java
Author: jdonnerstag
Date: Sat Dec 20 00:24:05 2008
New Revision: 728249
URL: http://svn.apache.org/viewvc?rev=728249&view=rev
Log:
wicket-1926: UrlValidator doesn't working when using a hostname in the url, e.g. http://localhost/test1
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/UrlValidator.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/validation/validator/UrlValidatorTest.java
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/UrlValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/UrlValidator.java?rev=728249&r1=728248&r2=728249&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/UrlValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/UrlValidator.java Sat Dec 20 00:24:05 2008
@@ -260,15 +260,13 @@
}
Matcher matchAsciiPat = Pattern.compile(LEGAL_ASCII_PATTERN).matcher(value);
- Matcher matchUrlPat = Pattern.compile(URL_PATTERN).matcher(value);
-
-
if (!matchAsciiPat.matches())
{
return false;
}
// Check the whole url address structure
+ Matcher matchUrlPat = Pattern.compile(URL_PATTERN).matcher(value);
if (!matchUrlPat.matches())
{
return false;
@@ -363,7 +361,6 @@
Matcher matchIPV4Pat = Pattern.compile(IP_V4_DOMAIN_PATTERN).matcher(hostIP);
ipV4Address = matchIPV4Pat.matches();
-
if (ipV4Address)
{
// this is an IP address so check components
@@ -429,24 +426,22 @@
segmentCount++;
}
}
- String topLevel = domainSegment[segmentCount - 1];
- if (topLevel.length() < 2 || topLevel.length() > 4)
- {
- return false;
- }
- // First letter of top level must be a alpha
- Matcher alphaMatcher = Pattern.compile(ALPHA_PATTERN).matcher(topLevel.substring(0, 1));
-
- if (!alphaMatcher.matches())
+ if (segmentCount > 1)
{
- return false;
- }
+ String topLevel = domainSegment[segmentCount - 1];
+ if (topLevel.length() < 2 || topLevel.length() > 4)
+ {
+ return false;
+ }
- // Make sure there's a host name preceding the authority.
- if (segmentCount < 2)
- {
- return false;
+ // First letter of top level must be a alpha
+ Matcher alphaMatcher = Pattern.compile(ALPHA_PATTERN).matcher(
+ topLevel.substring(0, 1));
+ if (!alphaMatcher.matches())
+ {
+ return false;
+ }
}
}
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/validation/validator/UrlValidatorTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/validation/validator/UrlValidatorTest.java?rev=728249&r1=728248&r2=728249&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/validation/validator/UrlValidatorTest.java (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/validation/validator/UrlValidatorTest.java Sat Dec 20 00:24:05 2008
@@ -25,12 +25,16 @@
*/
public class UrlValidatorTest extends TestCase
{
-
private final boolean printStatus = false;
- private final boolean printIndex = false;// print index that indicates current
- // scheme,host,port,path,
+ private final boolean printIndex = false; // print index that indicates current
+ // scheme,host,port,path,
+
+ private final boolean printDebug = true;
+ /**
+ *
+ */
@Override
protected void setUp()
{
@@ -40,6 +44,9 @@
}
}
+ /**
+ *
+ */
@Override
protected void tearDown()
{
@@ -91,7 +98,6 @@
{
System.out.println();
}
-
}
/**
@@ -107,6 +113,17 @@
UrlValidator urlVal = new UrlValidator(null, options);
assertTrue(urlVal.isValid("http://www.google.com"));
assertTrue(urlVal.isValid("http://www.google.com/"));
+
+ // some of the following combinations can not be properly modeled with the
+ // ResultPair
+ assertTrue(urlVal.isValid("http://localhost"));
+ assertTrue(urlVal.isValid("http://localhost/"));
+ assertTrue(urlVal.isValid("http://localhost:8080"));
+ assertTrue(urlVal.isValid("http://localhost/test1"));
+ assertTrue(urlVal.isValid("http://localhost/test1/"));
+ assertTrue(urlVal.isValid("http://localhost?action=view"));
+ assertTrue(urlVal.isValid("http://localhost/test1?action=view"));
+
int statusPerLine = 60;
int printed = 0;
if (printIndex)
@@ -115,6 +132,7 @@
}
do
{
+ String output = "";
StringBuffer testBuffer = new StringBuffer();
boolean expected = true;
for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex)
@@ -123,9 +141,17 @@
ResultPair[] part = (ResultPair[])testObjects[testPartsIndexIndex];
testBuffer.append(part[index].item);
expected &= part[index].valid;
+ if (printDebug)
+ {
+ output += "" + part[index].valid + ":";
+ }
}
String url = testBuffer.toString();
boolean result = urlVal.isValid(url);
+ if (printDebug && (expected != result))
+ {
+ System.out.println(output + " - " + expected + " - " + url);
+ }
assertEquals(url, expected, result);
if (printStatus)
{
@@ -179,6 +205,12 @@
assertTrue(UrlValidator.isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5"));
}
+ /**
+ *
+ * @param testPartsIndex
+ * @param testParts
+ * @return
+ */
static boolean incrementTestPartsIndex(int[] testPartsIndex, Object[] testParts)
{
boolean carry = true; // add 1 to lowest order part.
@@ -208,6 +240,10 @@
return (!maxIndex);
}
+ /**
+ *
+ * @return
+ */
private String testPartsIndextoString()
{
StringBuffer carryMsg = new StringBuffer("{");
@@ -255,7 +291,11 @@
new ResultPair("1.2.3", false), new ResultPair(".1.2.3.4", false),
new ResultPair("go.a", false), new ResultPair("go.a1a", true),
new ResultPair("go.1aa", false), new ResultPair("aaa.", false),
- new ResultPair(".aaa", false), new ResultPair("aaa", false), new ResultPair("", false) };
+ new ResultPair(".aaa", false), new ResultPair("aaa", true)
+ /*
+ * , new ResultPair("", false) In combination with "http:/" + "/test1" the expected result is
+ * true
+ */};
ResultPair[] testUrlPort = { new ResultPair(":80", true), new ResultPair(":65535", true),
new ResultPair(":0", true), new ResultPair("", true), new ResultPair(":-1", false),
new ResultPair(":65636", true), new ResultPair(":65a", false) };