This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5021-static-content-path
in repository https://gitbox.apache.org/repos/asf/struts.git


The following commit(s) were added to refs/heads/WW-5021-static-content-path by 
this push:
     new 1f70627  WW-5021 Adds missing validation for trailing "/"
1f70627 is described below

commit 1f70627058d74cf9911e1c52234437bb866b2bdf
Author: Lukasz Lenart <lukaszlen...@apache.org>
AuthorDate: Fri Jan 8 08:45:18 2021 +0100

    WW-5021 Adds missing validation for trailing "/"
---
 .../struts2/dispatcher/StaticContentLoader.java    |  7 ++++++-
 .../org/apache/struts2/default.properties          | 11 +++++-----
 .../org/apache/struts2/components/UIBeanTest.java  |  5 +++++
 .../dispatcher/DefaultStaticContentLoaderTest.java | 24 +++++-----------------
 4 files changed, 22 insertions(+), 25 deletions(-)

diff --git 
a/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java 
b/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
index da2fd7a..f3a15e5 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
@@ -84,11 +84,16 @@ public interface StaticContentLoader {
                     uiStaticContentPath,
                     StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH);
                 return StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH;
-            } else if(!uiStaticContentPath.startsWith("/")) {
+            } else if (!uiStaticContentPath.startsWith("/")) {
                 LOG.warn("\"{}\" must start with \"/\", but has been set to 
\"{}\", prepending the missing \"/\"!",
                     StrutsConstants.STRUTS_UI_STATIC_CONTENT_PATH,
                     uiStaticContentPath);
                 return "/" + uiStaticContentPath;
+            } else if (uiStaticContentPath.endsWith("/")) {
+                LOG.warn("\"{}\" must not end with \"/\", but has been set to 
\"{}\", removing all trailing \"/\"!",
+                    StrutsConstants.STRUTS_UI_STATIC_CONTENT_PATH,
+                    uiStaticContentPath);
+                return StringUtils.stripEnd(uiStaticContentPath, "/");
             } else {
                 LOG.debug("\"{}\" has been set to \"{}\"", 
StrutsConstants.STRUTS_UI_STATIC_CONTENT_PATH, uiStaticContentPath);
                 return uiStaticContentPath;
diff --git a/core/src/main/resources/org/apache/struts2/default.properties 
b/core/src/main/resources/org/apache/struts2/default.properties
index 60819c6..95a2bd4 100644
--- a/core/src/main/resources/org/apache/struts2/default.properties
+++ b/core/src/main/resources/org/apache/struts2/default.properties
@@ -83,11 +83,15 @@ struts.multipart.maxSize=2097152
 ### prior to a comma e.g. struts.action.extension=, or 
struts.action.extension=x,y,z,,
 struts.action.extension=action,,
 
-### Used by FilterDispatcher
+### Used by Dispatcher
 ### If true then Struts serves static content from inside its jar.
-### If false then the static content must be available at <context_path>/struts
+### If false then the static content must be available at <context_path>/static
 struts.serve.static=true
 
+### A path from which a static content is served, it must start with "/"
+### and it cannot end with "/"
+struts.ui.staticContentPath=/static
+
 ### Used by FilterDispatcher
 ### This is good for development where one wants changes to the static content 
be
 ### fetch on each request.
@@ -147,9 +151,6 @@ struts.ui.theme.expansion.token=~~~
 #sets the default template type. Either ftl, vm, or jsp
 struts.ui.templateSuffix=ftl
 
-### A path from which a static content is served in case of tags
-struts.ui.staticContentPath=/static
-
 ### Configuration reloading
 ### This will cause the configuration to reload struts.xml when it is changed
 ### struts.configuration.xml.reload=false
diff --git a/core/src/test/java/org/apache/struts2/components/UIBeanTest.java 
b/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
index 4eac690..e4b0c63 100644
--- a/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
+++ b/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
@@ -373,6 +373,11 @@ public class UIBeanTest extends StrutsInternalTestCase {
         field.setStaticContentPath("/content");
         // then
         assertEquals("/content", field.uiStaticContentPath);
+
+        // when
+        field.setStaticContentPath("/content/");
+        // then
+        assertEquals("/content", field.uiStaticContentPath);
     }
 
 }
diff --git 
a/core/src/test/java/org/apache/struts2/dispatcher/DefaultStaticContentLoaderTest.java
 
b/core/src/test/java/org/apache/struts2/dispatcher/DefaultStaticContentLoaderTest.java
index d712088..b472ce5 100644
--- 
a/core/src/test/java/org/apache/struts2/dispatcher/DefaultStaticContentLoaderTest.java
+++ 
b/core/src/test/java/org/apache/struts2/dispatcher/DefaultStaticContentLoaderTest.java
@@ -101,46 +101,32 @@ public class DefaultStaticContentLoaderTest extends 
StrutsInternalTestCase {
         }
     }
 
-    public void testSetNullUiStaticContentPath() {
+    public void testStaticContentPath() {
         // given
         DefaultStaticContentLoader loader = new DefaultStaticContentLoader();
 
         // when
         loader.setStaticContentPath(null);
-
         // then
         assertEquals(StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH, 
loader.uiStaticContentPath);
-    }
-
-    public void testSetEmptyUiStaticContentPath() {
-        // given
-        DefaultStaticContentLoader loader = new DefaultStaticContentLoader();
 
         // when
         loader.setStaticContentPath(" ");
-
         // then
         assertEquals(StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH, 
loader.uiStaticContentPath);
-    }
-
-    public void testSetUiStaticContentPathWithoutLeadingSlash() {
-        // given
-        DefaultStaticContentLoader loader = new DefaultStaticContentLoader();
 
         // when
         loader.setStaticContentPath("content");
-
         // then
         assertEquals("/content", loader.uiStaticContentPath);
-    }
-
-    public void testSetUiStaticContentPath() {
-        // given
-        DefaultStaticContentLoader loader = new DefaultStaticContentLoader();
 
         // when
         loader.setStaticContentPath("/content");
+        // then
+        assertEquals("/content", loader.uiStaticContentPath);
 
+        // when
+        loader.setStaticContentPath("/content/");
         // then
         assertEquals("/content", loader.uiStaticContentPath);
     }

Reply via email to