JCgH4164838Gh792C124B5 commented on a change in pull request #462:
URL: https://github.com/apache/struts/pull/462#discussion_r553431390
##########
File path:
core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
##########
@@ -57,4 +67,32 @@
*/
void findStaticResource(String path, HttpServletRequest request,
HttpServletResponse response) throws IOException;
+ class Validator {
+
+ private static final Logger LOG =
LogManager.getLogger(DefaultStaticContentLoader.class);
+
+ public static String validateStaticContentPath(String
uiStaticContentPath) {
+ if (StringUtils.isBlank(uiStaticContentPath)) {
+ LOG.warn("\"{}\" has been set to \"{}\", falling back into
default value \"{}\"",
+ StrutsConstants.STRUTS_UI_STATIC_CONTENT_PATH,
+ uiStaticContentPath,
+ StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH);
+ return StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH;
+ } else if ("/".equals(uiStaticContentPath)) {
+ LOG.warn("\"{}\" cannot be set to \"{}\", falling back into
default value \"{}\"",
+ StrutsConstants.STRUTS_UI_STATIC_CONTENT_PATH,
+ uiStaticContentPath,
+ StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH);
+ return StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH;
+ } else if(!uiStaticContentPath.startsWith("/")) {
Review comment:
Minor spacing item: "} else if(" could be "} else if ("
##########
File path:
core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
##########
@@ -57,4 +67,32 @@
*/
void findStaticResource(String path, HttpServletRequest request,
HttpServletResponse response) throws IOException;
+ class Validator {
+
+ private static final Logger LOG =
LogManager.getLogger(DefaultStaticContentLoader.class);
+
+ public static String validateStaticContentPath(String
uiStaticContentPath) {
+ if (StringUtils.isBlank(uiStaticContentPath)) {
+ LOG.warn("\"{}\" has been set to \"{}\", falling back into
default value \"{}\"",
+ StrutsConstants.STRUTS_UI_STATIC_CONTENT_PATH,
+ uiStaticContentPath,
+ StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH);
+ return StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH;
+ } else if ("/".equals(uiStaticContentPath)) {
+ LOG.warn("\"{}\" cannot be set to \"{}\", falling back into
default value \"{}\"",
+ StrutsConstants.STRUTS_UI_STATIC_CONTENT_PATH,
+ uiStaticContentPath,
+ StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH);
+ return StaticContentLoader.DEFAULT_STATIC_CONTENT_PATH;
+ } 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 {
Review comment:
I think there may be one validation condition missing from the checks
(trailing "/"), as it looks like that would break processing as well. Adding a
new clause like this:
```
} 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, "/");
}
```
before the final else might work. What do you think ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]