From commits-return-19501-archive-asf-public=cust-asf.ponee.io@struts.apache.org Fri Jan 8 07:45:26 2021 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mxout1-ec2-va.apache.org (mxout1-ec2-va.apache.org [3.227.148.255]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id 44DE3180670 for ; Fri, 8 Jan 2021 08:45:26 +0100 (CET) Received: from mail.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mxout1-ec2-va.apache.org (ASF Mail Server at mxout1-ec2-va.apache.org) with SMTP id 7F2D745EEB for ; Fri, 8 Jan 2021 07:45:25 +0000 (UTC) Received: (qmail 68984 invoked by uid 500); 8 Jan 2021 07:45:24 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 68966 invoked by uid 99); 8 Jan 2021 07:45:24 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jan 2021 07:45:24 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 8BC14820F7; Fri, 8 Jan 2021 07:45:24 +0000 (UTC) Date: Fri, 08 Jan 2021 07:45:24 +0000 To: "commits@struts.apache.org" Subject: [struts] branch WW-5021-static-content-path updated: WW-5021 Adds missing validation for trailing "/" MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <161009192447.26303.2249501569733453006@gitbox.apache.org> From: lukaszlenart@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: struts X-Git-Refname: refs/heads/WW-5021-static-content-path X-Git-Reftype: branch X-Git-Oldrev: f956910d20bbc162b4ba9bbc8899f88df9f8917a X-Git-Newrev: 1f70627058d74cf9911e1c52234437bb866b2bdf X-Git-Rev: 1f70627058d74cf9911e1c52234437bb866b2bdf X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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 /struts +### If false then the static content must be available at /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); }