Merge branch '5.3.x' into main

This commit is contained in:
Rossen Stoyanchev
2021-11-09 10:23:14 +00:00
3 changed files with 23 additions and 14 deletions

View File

@@ -36,8 +36,9 @@ import org.springframework.lang.Nullable;
public abstract class LogFormatUtils {
/**
* Variant of {@link #formatValue(Object, int, boolean)} and a convenience
* method that truncates at 100 characters when {@code limitLength} is set.
* Convenience variant of {@link #formatValue(Object, int, boolean)} that
* limits the length of a log message to 100 characters and also replaces
* newline characters if {@code limitLength} is set to "true".
* @param value the value to format
* @param limitLength whether to truncate the value at a length of 100
* @return the formatted value

View File

@@ -404,16 +404,18 @@ public class UrlPathHelper {
* </ul>
*/
private static String getSanitizedPath(final String path) {
int index = path.indexOf("//");
if (index >= 0) {
StringBuilder sanitized = new StringBuilder(path);
while (index != -1) {
sanitized.deleteCharAt(index);
index = sanitized.indexOf("//", index);
}
return sanitized.toString();
int start = path.indexOf("//");
if (start == -1) {
return path;
}
return path;
char[] content = path.toCharArray();
int slowIndex = start;
for (int fastIndex = start + 1; fastIndex < content.length; fastIndex++) {
if (content[fastIndex] != '/' || content[slowIndex] != '/') {
content[++slowIndex] = content[fastIndex];
}
}
return new String(content, 0, slowIndex + 1);
}
/**
@@ -531,7 +533,7 @@ public class UrlPathHelper {
*/
public String getOriginatingQueryString(HttpServletRequest request) {
if ((request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE) != null) ||
(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE) != null)) {
(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE) != null)) {
return (String) request.getAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE);
}
else {

View File

@@ -232,12 +232,12 @@ class UrlPathHelperTests {
request.setContextPath("/SPR-12372");
request.setPathInfo(null);
request.setServletPath("/foo/bar/");
request.setRequestURI("/SPR-12372/foo//bar/");
request.setRequestURI("/SPR-12372/foo///bar/");
assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/foo/bar/");
request.setServletPath("/foo/bar/");
request.setRequestURI("/SPR-12372/foo/bar//");
request.setRequestURI("////SPR-12372/foo/bar//");
assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/foo/bar/");
@@ -246,6 +246,12 @@ class UrlPathHelperTests {
request.setRequestURI("/SPR-12372/foo/bar//");
assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/foo/bar//");
// "enhance" case
request.setServletPath("/foo/bar//");
request.setRequestURI("/SPR-12372////////////////////////foo//////////////////bar////////////////////");
assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/foo/bar//");
}
@Test