Skip to content

Commit

Permalink
WW-5021 Adds missing validation for trailing "/"
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Jan 8, 2021
1 parent f956910 commit 1f70627
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ public static String validateStaticContentPath(String uiStaticContentPath) {
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;
Expand Down
11 changes: 6 additions & 5 deletions core/src/main/resources/org/apache/struts2/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ public void testSetNullUiStaticContentPath() {
field.setStaticContentPath("/content");
// then
assertEquals("/content", field.uiStaticContentPath);

// when
field.setStaticContentPath("/content/");
// then
assertEquals("/content", field.uiStaticContentPath);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,46 +101,32 @@ public void testFindStaticResourceIllegalStateException() {
}
}

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);
}
Expand Down

0 comments on commit 1f70627

Please sign in to comment.