Consistent comma splitting without regex overhead

Issue: SPR-14635
(cherry picked from commit 03609c1)
This commit is contained in:
Juergen Hoeller
2016-08-30 23:56:58 +02:00
parent 3b91dec462
commit d8f7347000
10 changed files with 98 additions and 98 deletions

View File

@@ -50,6 +50,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@@ -198,7 +199,8 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
* {@link HttpServletRequest#getContextPath()} which states it can be
* an empty string, or it must start with a "/" and not end with a "/".
* @param contextPath a valid contextPath
* @throws IllegalArgumentException if the contextPath is not a valid {@link HttpServletRequest#getContextPath()}
* @throws IllegalArgumentException if the contextPath is not a valid
* {@link HttpServletRequest#getContextPath()}
*/
public void setContextPath(String contextPath) {
MockMvcWebConnection.validateContextPath(contextPath);
@@ -211,9 +213,9 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
private void authType(MockHttpServletRequest request) {
String authorization = header("Authorization");
if (authorization != null) {
String[] authzParts = authorization.split(": ");
request.setAuthType(authzParts[0]);
String[] authSplit = StringUtils.split(authorization, ": ");
if (authSplit != null) {
request.setAuthType(authSplit[0]);
}
}
@@ -263,8 +265,8 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
while (tokens.hasMoreTokens()) {
String cookieName = tokens.nextToken().trim();
if (!tokens.hasMoreTokens()) {
throw new IllegalArgumentException("Expected value for cookie name '" + cookieName
+ "'. Full cookie was " + cookieHeaderValue);
throw new IllegalArgumentException("Expected value for cookie name '" + cookieName +
"'. Full cookie was " + cookieHeaderValue);
}
String cookieValue = tokens.nextToken().trim();
processCookie(request, cookies, new Cookie(cookieName, cookieValue));
@@ -352,9 +354,9 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
request.addPreferredLocale(Locale.getDefault());
}
else {
String[] locales = locale.split(", ");
for (int i = locales.length - 1; i >= 0; i--) {
request.addPreferredLocale(parseLocale(locales[i]));
String[] tokens = StringUtils.tokenizeToStringArray(locale, ",");
for (int i = tokens.length - 1; i >= 0; i--) {
request.addPreferredLocale(parseLocale(tokens[i]));
}
}
}