struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tschnei...@apache.org
Subject svn commit: r508879 - in /struts/struts2: branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java trunk/core/src/test/java/org/apache/struts2/views/util/UrlHelperTest.java
Date Sun, 18 Feb 2007 06:32:02 GMT
Author: tschneider
Date: Sat Feb 17 22:32:02 2007
New Revision: 508879

URL: http://svn.apache.org/viewvc?view=rev&rev=508879
Log:
WW-1709 fixed nullpointer when scheme is null

Modified:
    struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/util/UrlHelperTest.java

Modified: struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java?view=diff&rev=508879&r1=508878&r2=508879
==============================================================================
--- struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java
(original)
+++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java
Sat Feb 17 22:32:02 2007
@@ -103,10 +103,12 @@
             link.append("://");
             link.append(request.getServerName());
 
-            if ((scheme.equals("http") && (httpPort != DEFAULT_HTTP_PORT)) || (scheme.equals("https")
&& httpsPort != DEFAULT_HTTPS_PORT))
-            {
-                link.append(":");
-                link.append(scheme.equals("http") ? httpPort : httpsPort);
+            if (scheme != null) {
+                if ((scheme.equals("http") && (httpPort != DEFAULT_HTTP_PORT)) ||
(scheme.equals("https") && httpsPort != DEFAULT_HTTPS_PORT))
+                {
+                    link.append(":");
+                    link.append(scheme.equals("http") ? httpPort : httpsPort);
+                }
             }
         }
         else if (

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/util/UrlHelperTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/util/UrlHelperTest.java?view=diff&rev=508879&r1=508878&r2=508879
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/util/UrlHelperTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/util/UrlHelperTest.java
Sat Feb 17 22:32:02 2007
@@ -90,7 +90,26 @@
            expectedUrl, url.toString());
     }
 
+    public void testForceAddNullSchemeHostAndPort() throws Exception {
+        String expectedUrl = "http://localhost/contextPath/path1/path2/myAction.action";
 
+        Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
+        mockHttpServletRequest.expectAndReturn("getScheme", "http");
+        mockHttpServletRequest.expectAndReturn("getServerName", "localhost");
+        mockHttpServletRequest.expectAndReturn("getContextPath",
+            "/contextPath");
+
+        Mock mockHttpServletResponse = new Mock(HttpServletResponse.class);
+        mockHttpServletResponse.expectAndReturn("encodeURL", expectedUrl,
+            expectedUrl);
+
+        String result = UrlHelper.buildUrl("/path1/path2/myAction.action",
+            (HttpServletRequest) mockHttpServletRequest.proxy(),
+            (HttpServletResponse) mockHttpServletResponse.proxy(), null,
+            null, true, true, true);
+        assertEquals(expectedUrl, result);
+        mockHttpServletRequest.verify();
+    }
 
     public void testBuildWithRootContext() {
         String expectedUrl = "/MyAction.action";



Mime
View raw message