Consistent comma splitting without regex overhead
Issue: SPR-14635
(cherry picked from commit 03609c1)
This commit is contained in:
@@ -474,7 +474,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
List<HttpMethod> result = new ArrayList<HttpMethod>();
|
||||
String value = getFirst(ACCESS_CONTROL_ALLOW_METHODS);
|
||||
if (value != null) {
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(value, ",", true, true);
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(value, ",");
|
||||
for (String token : tokens) {
|
||||
HttpMethod resolved = HttpMethod.resolve(token);
|
||||
if (resolved != null) {
|
||||
@@ -578,10 +578,10 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
* as specified by the {@code Accept-Charset} header.
|
||||
*/
|
||||
public List<Charset> getAcceptCharset() {
|
||||
List<Charset> result = new ArrayList<Charset>();
|
||||
String value = getFirst(ACCEPT_CHARSET);
|
||||
if (value != null) {
|
||||
String[] tokens = value.split(",\\s*");
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(value, ",");
|
||||
List<Charset> result = new ArrayList<Charset>(tokens.length);
|
||||
for (String token : tokens) {
|
||||
int paramIdx = token.indexOf(';');
|
||||
String charsetName;
|
||||
@@ -595,8 +595,11 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
result.add(Charset.forName(charsetName));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -615,8 +618,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
public Set<HttpMethod> getAllow() {
|
||||
String value = getFirst(ALLOW);
|
||||
if (!StringUtils.isEmpty(value)) {
|
||||
List<HttpMethod> result = new LinkedList<HttpMethod>();
|
||||
String[] tokens = value.split(",\\s*");
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(value, ",");
|
||||
List<HttpMethod> result = new ArrayList<HttpMethod>(tokens.length);
|
||||
for (String token : tokens) {
|
||||
HttpMethod resolved = HttpMethod.resolve(token);
|
||||
if (resolved != null) {
|
||||
@@ -691,7 +694,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
StringBuilder builder = new StringBuilder("form-data; name=\"");
|
||||
builder.append(name).append('\"');
|
||||
if (filename != null) {
|
||||
if(charset == null || Charset.forName("US-ASCII").equals(charset)) {
|
||||
if (charset == null || charset.name().equals("US-ASCII")) {
|
||||
builder.append("; filename=\"");
|
||||
builder.append(filename).append('\"');
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public abstract class HttpRange {
|
||||
}
|
||||
ranges = ranges.substring(BYTE_RANGE_PREFIX.length());
|
||||
|
||||
String[] tokens = ranges.split(",\\s*");
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(ranges, ",");
|
||||
List<HttpRange> result = new ArrayList<HttpRange>(tokens.length);
|
||||
for (String token : tokens) {
|
||||
result.add(parseRange(token));
|
||||
|
||||
@@ -438,7 +438,7 @@ public class MediaType extends MimeType implements Serializable {
|
||||
if (!StringUtils.hasLength(mediaTypes)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
String[] tokens = mediaTypes.split(",\\s*");
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(mediaTypes, ",");
|
||||
List<MediaType> result = new ArrayList<MediaType>(tokens.length);
|
||||
for (String token : tokens) {
|
||||
result.add(parseMediaType(token));
|
||||
|
||||
@@ -673,7 +673,7 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
UriComponentsBuilder adaptFromForwardedHeaders(HttpHeaders headers) {
|
||||
String forwardedHeader = headers.getFirst("Forwarded");
|
||||
if (StringUtils.hasText(forwardedHeader)) {
|
||||
String forwardedToUse = StringUtils.commaDelimitedListToStringArray(forwardedHeader)[0];
|
||||
String forwardedToUse = StringUtils.tokenizeToStringArray(forwardedHeader, ",")[0];
|
||||
Matcher matcher = FORWARDED_HOST_PATTERN.matcher(forwardedToUse);
|
||||
if (matcher.find()) {
|
||||
host(matcher.group(1).trim());
|
||||
@@ -686,10 +686,9 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
else {
|
||||
String hostHeader = headers.getFirst("X-Forwarded-Host");
|
||||
if (StringUtils.hasText(hostHeader)) {
|
||||
String[] hosts = StringUtils.commaDelimitedListToStringArray(hostHeader);
|
||||
String hostToUse = hosts[0];
|
||||
if (hostToUse.contains(":")) {
|
||||
String[] hostAndPort = StringUtils.split(hostToUse, ":");
|
||||
String hostToUse = StringUtils.tokenizeToStringArray(hostHeader, ",")[0];
|
||||
String[] hostAndPort = StringUtils.split(hostToUse, ":");
|
||||
if (hostAndPort != null) {
|
||||
host(hostAndPort[0]);
|
||||
port(Integer.parseInt(hostAndPort[1]));
|
||||
}
|
||||
@@ -701,14 +700,12 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
|
||||
String portHeader = headers.getFirst("X-Forwarded-Port");
|
||||
if (StringUtils.hasText(portHeader)) {
|
||||
String[] ports = StringUtils.commaDelimitedListToStringArray(portHeader);
|
||||
port(Integer.parseInt(ports[0]));
|
||||
port(Integer.parseInt(StringUtils.tokenizeToStringArray(portHeader, ",")[0]));
|
||||
}
|
||||
|
||||
String protocolHeader = headers.getFirst("X-Forwarded-Proto");
|
||||
if (StringUtils.hasText(protocolHeader)) {
|
||||
String[] protocols = StringUtils.commaDelimitedListToStringArray(protocolHeader);
|
||||
scheme(protocols[0]);
|
||||
scheme(StringUtils.tokenizeToStringArray(protocolHeader, ",")[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user