wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r1058239 - in /incubator/wink/trunk/wink-common/src: main/java/org/apache/wink/common/internal/UriBuilderImpl.java test/java/org/apache/wink/common/internal/UriBuilderImplTest.java
Date Wed, 12 Jan 2011 17:15:57 GMT
Author: bluk
Date: Wed Jan 12 17:15:57 2011
New Revision: 1058239

URL: http://svn.apache.org/viewvc?rev=1058239&view=rev
Log:
Fix a stackoverflow in UriBuilder

Thanks to Koos Gadellaa for reporting the issue.

See [WINK-331]

Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/UriBuilderImpl.java
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/UriBuilderImplTest.java

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/UriBuilderImpl.java?rev=1058239&r1=1058238&r2=1058239&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/UriBuilderImpl.java
(original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/UriBuilderImpl.java
Wed Jan 12 17:15:57 2011
@@ -550,6 +550,7 @@ public class UriBuilderImpl extends UriB
         }
 
         if (isFirstCall) {
+            isFirstCall = false;
             if (path.indexOf(":") != -1) { //$NON-NLS-1$
                 // we need to parse this as scheme:scheme-specific-part#fragment
                 // for
@@ -572,7 +573,6 @@ public class UriBuilderImpl extends UriB
                     }
                 }
             }
-            isFirstCall = false;
         }
 
         // strip off the authority prefix if present
@@ -753,10 +753,10 @@ public class UriBuilderImpl extends UriB
     public UriBuilder replacePath(String path) {
         logger.trace("replacePath({}) entry", path); //$NON-NLS-1$
         if (isFirstCall) {
+            isFirstCall = false;
             if (path == null) {
                 throw new IllegalArgumentException(Messages.getMessage("variableIsNull",
"path")); //$NON-NLS-1$ //$NON-NLS-2$
             }
-            isFirstCall = false;
         }
         if (path == null) {
             logger.trace("path is null. resetting"); //$NON-NLS-1$

Modified: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/UriBuilderImplTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/UriBuilderImplTest.java?rev=1058239&r1=1058238&r2=1058239&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/UriBuilderImplTest.java
(original)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/UriBuilderImplTest.java
Wed Jan 12 17:15:57 2011
@@ -356,9 +356,12 @@ public class UriBuilderImplTest extends 
         uriBuilder = UriBuilder.fromUri(new URI("foo://localhost:8080/com/ibm?name=myname#first"));
         uriBuilder = uriBuilder.uri(new URI("//localhost:8080/com/ibm?name=myname#last"));
         assertEquals("foo://localhost:8080/com/ibm?name=myname#last", uriBuilder.build().toString());
-        
-        uriBuilder = UriBuilder.fromUri(new URI("http://myserver/dm/atom/library/%5B@Pgistest/@RMain.nsf%5D/feed"));
-        assertEquals("http://myserver/dm/atom/library/%5B@Pgistest/@RMain.nsf%5D/feed", uriBuilder.build().toString());
+
+        uriBuilder =
+            UriBuilder
+                .fromUri(new URI("http://myserver/dm/atom/library/%5B@Pgistest/@RMain.nsf%5D/feed"));
+        assertEquals("http://myserver/dm/atom/library/%5B@Pgistest/@RMain.nsf%5D/feed", uriBuilder
+            .build().toString());
     }
 
     public void testClone() {
@@ -570,26 +573,37 @@ public class UriBuilderImplTest extends 
         assertEquals("http://localhost?something", UriBuilder.fromUri("http://localhost?something")
             .build().toString());
     }
-    
 
     public void testWithPathTemplate() {
         UriBuilder builder = UriBuilder.fromPath("/myResource/{entity_id: [0-9]+}");
         assertEquals("/myResource/3", builder.build("3").toString());
-        
+
         builder = UriBuilder.fromPath("http://localhost:8080/myResource");
         builder.path("{entity_id: [0-9]+}");
         assertEquals("http://localhost:8080/myResource/3", builder.build("3").toString());
     }
 
-
     public void testWithQueryEncoded() throws Exception {
         URL url = new URL("http://localhost:8080/myResource?q={abcd}");
-        // URI.toURL() will escape characters if we use one of the multi-param constructors
-        URI constructedURI = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
url.getPort(),url.getPath(), url.getQuery(), null);
+        // URI.toURL() will escape characters if we use one of the multi-param
+        // constructors
+        URI constructedURI =
+            new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url
+                .getPath(), url.getQuery(), null);
         assertEquals("http://localhost:8080/myResource?q=%7Babcd%7D", constructedURI.toString());
-        
+
         UriBuilder builder = UriBuilder.fromUri("http://localhost:8080/myResource");
         builder.queryParam("q", "%7Babcd%7D");
         assertEquals("http://localhost:8080/myResource?q=%7Babcd%7D", builder.build().toString());
     }
+
+    public void testNoOverflow() throws Exception {
+        UriBuilder builder = UriBuilder.fromPath("a:/a:/b#c");
+        assertEquals("a:/a:/b#c", builder.build().toString());
+
+        builder = UriBuilder.fromPath("http://localhost/");
+        builder.path("a:/a:/b");
+        builder.fragment("c");
+        assertEquals("http://localhost/a:/a:/b#c", builder.build().toString());
+    }
 }



Mime
View raw message