Updates to*Case() to use Locale.ROOT

This commit is contained in:
spencergibb
2024-10-18 10:53:24 -04:00
committed by Oleg Zhurakousky
parent b65577d515
commit 900d03f816
83 changed files with 262 additions and 178 deletions

View File

@@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.springframework.http.HttpHeaders;
@@ -59,7 +60,7 @@ public final class HeaderUtils {
HttpHeaders result = new HttpHeaders();
for (String name : headers.keySet()) {
Object value = headers.get(name);
name = name.toLowerCase();
name = name.toLowerCase(Locale.ROOT);
if (!IGNORED.containsKey(name) && !ignoredHeders.contains(name)) {
Collection<?> values = multi(value);
for (Object object : values) {
@@ -80,7 +81,7 @@ public final class HeaderUtils {
HttpHeaders result = new HttpHeaders();
for (String name : request.keySet()) {
List<String> value = request.get(name);
name = name.toLowerCase();
name = name.toLowerCase(Locale.ROOT);
if (!IGNORED.containsKey(name) && !REQUEST_ONLY.containsKey(name) && !ignoredHeders.contains(name) && !requestOnlyHeaders.contains(name)) {
result.put(name, value);
}
@@ -97,10 +98,10 @@ public final class HeaderUtils {
Map<String, Object> map = new LinkedHashMap<>();
for (String name : headers.keySet()) {
Collection<?> values = multi(headers.get(name));
name = name.toLowerCase();
name = name.toLowerCase(Locale.ROOT);
Object value = values == null ? null
: (values.size() == 1 ? values.iterator().next() : values);
if (name.toLowerCase().equals(HttpHeaders.CONTENT_TYPE.toLowerCase())) {
if (name.toLowerCase(Locale.ROOT).equals(HttpHeaders.CONTENT_TYPE.toLowerCase(Locale.ROOT))) {
name = MessageHeaders.CONTENT_TYPE;
}
map.put(name, value);

View File

@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
@@ -300,13 +301,13 @@ public class FluxRestApplicationTests {
@PostMapping({ "/uppercase", "/transform", "/post/more" })
public Flux<?> uppercase(@RequestBody List<String> flux) {
return Flux.fromIterable(flux).log()
.map(value -> "[" + value.trim().toUpperCase() + "]");
.map(value -> "[" + value.trim().toUpperCase(Locale.ROOT) + "]");
}
@PostMapping({ "/alt" })
public Mono<ResponseEntity<?>> alt(@RequestBody List<String> flux) {
Publisher<?> result = Flux.fromIterable(flux)
.map(value -> "[" + value.trim().toUpperCase() + "]");
.map(value -> "[" + value.trim().toUpperCase(Locale.ROOT) + "]");
return Flux.from(result).log()
.then(Mono.fromSupplier(() -> ResponseEntity.ok(result)));
}
@@ -314,12 +315,12 @@ public class FluxRestApplicationTests {
@PostMapping("/upFoos")
public Flux<Foo> upFoos(@RequestBody List<Foo> list) {
return Flux.fromIterable(list).log()
.map(value -> new Foo(value.getValue().trim().toUpperCase()));
.map(value -> new Foo(value.getValue().trim().toUpperCase(Locale.ROOT)));
}
@GetMapping("/uppercase/{id}")
public Mono<ResponseEntity<?>> uppercaseGet(@PathVariable String id) {
return Mono.just(id).map(value -> "[" + value.trim().toUpperCase() + "]")
return Mono.just(id).map(value -> "[" + value.trim().toUpperCase(Locale.ROOT) + "]")
.flatMap(body -> Mono.just(ResponseEntity.ok(body)));
}
@@ -339,7 +340,7 @@ public class FluxRestApplicationTests {
public Flux<Map<String, String>> maps(
@RequestBody List<Map<String, String>> flux) {
return Flux.fromIterable(flux).map(value -> {
value.put("value", value.get("value").trim().toUpperCase());
value.put("value", value.get("value").trim().toUpperCase(Locale.ROOT));
return value;
});
}

View File

@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
@@ -289,18 +290,18 @@ public class MvcRestApplicationTests {
@PostMapping({ "/uppercase", "/transform", "/post/more" })
public Flux<?> uppercase(@RequestBody List<String> flux) {
return Flux.fromIterable(flux).log()
.map(value -> "[" + value.trim().toUpperCase() + "]");
.map(value -> "[" + value.trim().toUpperCase(Locale.ROOT) + "]");
}
@PostMapping("/upFoos")
public Flux<Foo> upFoos(@RequestBody List<Foo> list) {
return Flux.fromIterable(list).log()
.map(value -> new Foo(value.getValue().trim().toUpperCase()));
.map(value -> new Foo(value.getValue().trim().toUpperCase(Locale.ROOT)));
}
@GetMapping("/uppercase/{id}")
public Mono<?> uppercaseGet(@PathVariable String id) {
return Mono.just(id).map(value -> "[" + value.trim().toUpperCase() + "]");
return Mono.just(id).map(value -> "[" + value.trim().toUpperCase(Locale.ROOT) + "]");
}
@GetMapping("/wrap/{id}")
@@ -318,7 +319,7 @@ public class MvcRestApplicationTests {
public Flux<Map<String, String>> maps(
@RequestBody List<Map<String, String>> flux) {
return Flux.fromIterable(flux).map(value -> {
value.put("value", value.get("value").trim().toUpperCase());
value.put("value", value.get("value").trim().toUpperCase(Locale.ROOT));
return value;
});
}

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.function.test;
import java.util.Locale;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
@@ -54,7 +55,7 @@ public class ExplicitNonFunctionalTests {
@Override
public String apply(String value) {
return value.toUpperCase();
return value.toUpperCase(Locale.ROOT);
}
}

View File

@@ -19,6 +19,7 @@ package org.springframework.cloud.function.test;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
@@ -111,7 +112,7 @@ public class FunctionalExporterTests {
Function<Message<Person>, Message<String>> uppercase() {
return value -> {
headers.putAll(value.getHeaders());
return MessageBuilder.withPayload(value.getPayload().getName().toUpperCase())
return MessageBuilder.withPayload(value.getPayload().getName().toUpperCase(Locale.ROOT))
.copyHeaders(value.getHeaders()).build();
};
}

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.function.test;
import java.util.Locale;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
@@ -50,7 +51,7 @@ public class FunctionalTests {
@Override
public String apply(String value) {
return value.toUpperCase();
return value.toUpperCase(Locale.ROOT);
}
}

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.function.test;
import java.util.List;
import java.util.Locale;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -54,7 +55,7 @@ public class FunctionalWithInputListTests {
@Override
public Foo apply(List<Foo> value) {
return new Foo(value.stream().map(foo -> foo.getValue().toUpperCase())
return new Foo(value.stream().map(foo -> foo.getValue().toUpperCase(Locale.ROOT))
.collect(Collectors.joining()));
}

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.function.test;
import java.time.Duration;
import java.util.Locale;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -62,7 +63,7 @@ public class FunctionalWithInputSetTests {
@Override
public Foo apply(Set<Foo> value) {
return new Foo(value.stream().map(foo -> foo.getValue().toUpperCase())
return new Foo(value.stream().map(foo -> foo.getValue().toUpperCase(Locale.ROOT))
.collect(Collectors.joining()));
}

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.function.test;
import java.util.Locale;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
@@ -57,7 +58,7 @@ public class HeadersToMessageTests {
@Override
public Message<String> apply(Message<String> request) {
Message<String> message = MessageBuilder
.withPayload(request.getPayload().toUpperCase())
.withPayload(request.getPayload().toUpperCase(Locale.ROOT))
.setHeader("X-Content-Type", "application/xml")
.setHeader("foo", "bar").build();
return message;

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.function.test;
import java.util.Locale;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
@@ -54,7 +55,7 @@ public class ImplicitNonFunctionalTests {
@Bean
public Function<String, String> uppercase() {
return value -> value.toUpperCase();
return value -> value.toUpperCase(Locale.ROOT);
}
}

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.function.test;
import java.util.Locale;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
@@ -60,7 +61,7 @@ public class PojoTests {
@Override
public Foo apply(Foo value) {
return new Foo(value.getValue().toUpperCase());
return new Foo(value.getValue().toUpperCase(Locale.ROOT));
}
}

View File

@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -278,7 +279,7 @@ public class HttpGetIntegrationTests {
@Bean({ "uppercase", "post/more" })
public Function<Flux<String>, Flux<String>> uppercase() {
return flux -> flux.log()
.map(value -> "(" + value.trim().toUpperCase() + ")");
.map(value -> "(" + value.trim().toUpperCase(Locale.ROOT) + ")");
}
@Bean

View File

@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -410,37 +411,37 @@ public class HttpPostIntegrationTests {
@Bean({ "uppercase", "transform", "post/more" })
public Function<Flux<String>, Flux<String>> uppercase() {
return flux -> flux.log()
.map(value -> "(" + value.trim().toUpperCase() + ")");
.map(value -> "(" + value.trim().toUpperCase(Locale.ROOT) + ")");
}
@Bean
public Function<String, String> bareUppercase() {
return value -> "(" + value.trim().toUpperCase() + ")";
return value -> "(" + value.trim().toUpperCase(Locale.ROOT) + ")";
}
@Bean
public Function<Message<String>, Message<String>> messages() {
return value -> MessageBuilder
.withPayload("(" + value.getPayload().trim().toUpperCase() + ")")
.withPayload("(" + value.getPayload().trim().toUpperCase(Locale.ROOT) + ")")
.copyHeaders(value.getHeaders()).build();
}
@Bean
public Function<Flux<Message<String>>, Flux<Message<String>>> headers() {
return flux -> flux.map(value -> MessageBuilder
.withPayload("(" + value.getPayload().trim().toUpperCase() + ")")
.withPayload("(" + value.getPayload().trim().toUpperCase(Locale.ROOT) + ")")
.setHeader("foo", "bar").build());
}
@Bean
public Function<Flux<Foo>, Flux<Foo>> upFoos() {
return flux -> flux.log()
.map(value -> new Foo(value.getValue().trim().toUpperCase()));
.map(value -> new Foo(value.getValue().trim().toUpperCase(Locale.ROOT)));
}
@Bean
public Function<Foo, Foo> bareUpFoos() {
return value -> new Foo(value.getValue().trim().toUpperCase());
return value -> new Foo(value.getValue().trim().toUpperCase(Locale.ROOT));
}
@Bean
@@ -464,7 +465,7 @@ public class HttpPostIntegrationTests {
@Bean
public Function<Flux<HashMap<String, String>>, Flux<Map<String, String>>> maps() {
return flux -> flux.map(value -> {
value.put("value", value.get("value").trim().toUpperCase());
value.put("value", value.get("value").trim().toUpperCase(Locale.ROOT));
return value;
});
}
@@ -473,7 +474,7 @@ public class HttpPostIntegrationTests {
@Qualifier("foos")
public Function<String, Foo> qualifier() {
return value -> {
return new Foo("[" + value.trim().toUpperCase() + "]");
return new Foo("[" + value.trim().toUpperCase(Locale.ROOT) + "]");
};
}

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.function.web.function;
import java.net.URI;
import java.util.Locale;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
@@ -66,12 +67,12 @@ public class FunctionEndpointInitializerMVCTests {
@Bean
public Function<String, String> uppercase() {
return s -> s.toUpperCase();
return s -> s.toUpperCase(Locale.ROOT);
}
@Bean
public Function<String, String> lowercase() {
return s -> s.toLowerCase();
return s -> s.toLowerCase(Locale.ROOT);
}
@Bean

View File

@@ -19,6 +19,7 @@ package org.springframework.cloud.function.web.function;
import java.net.URI;
import java.time.Duration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Consumer;
@@ -196,11 +197,11 @@ public class FunctionEndpointInitializerTests {
}
public Function<String, String> uppercase() {
return s -> s.toUpperCase();
return s -> s.toUpperCase(Locale.ROOT);
}
public Function<String, String> lowercase() {
return s -> s.toLowerCase();
return s -> s.toLowerCase(Locale.ROOT);
}
public Function<String, String> reverse() {

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.function.web.function;
import java.net.URI;
import java.util.Locale;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
@@ -69,7 +70,7 @@ public class UserSubmittedTests {
@Bean
public Function<String, String> echo() {
return s -> s.toUpperCase();
return s -> s.toUpperCase(Locale.ROOT);
}
}

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.function.web.mvc;
import java.net.URI;
import java.util.Locale;
import java.util.function.Function;
import org.junit.jupiter.api.Disabled;
@@ -77,7 +78,7 @@ public class DefaultRouteTests {
@Bean
public Function<Flux<String>, Flux<String>> uppercase() {
return flux -> flux.map(value -> value.toUpperCase());
return flux -> flux.map(value -> value.toUpperCase(Locale.ROOT));
}
}

View File

@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -292,7 +293,7 @@ public class HttpGetIntegrationTests {
@Bean({ "uppercase", "post/more" })
public Function<Flux<String>, Flux<String>> uppercase() {
return flux -> flux.log()
.map(value -> "(" + value.trim().toUpperCase() + ")");
.map(value -> "(" + value.trim().toUpperCase(Locale.ROOT) + ")");
}
@Bean

View File

@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -348,37 +349,37 @@ public class HttpPostIntegrationTests {
@Bean({ "uppercase", "transform", "post/more" })
public Function<Flux<String>, Flux<String>> uppercase() {
return flux -> flux.log()
.map(value -> "(" + value.trim().toUpperCase() + ")");
.map(value -> "(" + value.trim().toUpperCase(Locale.ROOT) + ")");
}
@Bean
public Function<String, String> bareUppercase() {
return value -> "(" + value.trim().toUpperCase() + ")";
return value -> "(" + value.trim().toUpperCase(Locale.ROOT) + ")";
}
@Bean
public Function<Message<String>, Message<String>> messages() {
return value -> MessageBuilder
.withPayload("(" + value.getPayload().trim().toUpperCase() + ")")
.withPayload("(" + value.getPayload().trim().toUpperCase(Locale.ROOT) + ")")
.copyHeaders(value.getHeaders()).build();
}
@Bean
public Function<Flux<Message<String>>, Flux<Message<String>>> headers() {
return flux -> flux.map(value -> MessageBuilder
.withPayload("(" + value.getPayload().trim().toUpperCase() + ")")
.withPayload("(" + value.getPayload().trim().toUpperCase(Locale.ROOT) + ")")
.setHeader("foo", "bar").build());
}
@Bean
public Function<Flux<Foo>, Flux<Foo>> upFoos() {
return flux -> flux.log()
.map(value -> new Foo(value.getValue().trim().toUpperCase()));
.map(value -> new Foo(value.getValue().trim().toUpperCase(Locale.ROOT)));
}
@Bean
public Function<Foo, Foo> bareUpFoos() {
return value -> new Foo(value.getValue().trim().toUpperCase());
return value -> new Foo(value.getValue().trim().toUpperCase(Locale.ROOT));
}
@Bean
@@ -394,7 +395,7 @@ public class HttpPostIntegrationTests {
@Bean
public Function<Flux<HashMap<String, String>>, Flux<Map<String, String>>> maps() {
return flux -> flux.map(value -> {
value.put("value", value.get("value").trim().toUpperCase());
value.put("value", value.get("value").trim().toUpperCase(Locale.ROOT));
return value;
});
}
@@ -402,7 +403,7 @@ public class HttpPostIntegrationTests {
@Bean
@Qualifier("foos")
public Function<String, Foo> qualifier() {
return value -> new Foo("[" + value.trim().toUpperCase() + "]");
return value -> new Foo("[" + value.trim().toUpperCase(Locale.ROOT) + "]");
}
@Bean

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.function.web.mvc;
import java.net.URI;
import java.util.List;
import java.util.Locale;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
@@ -93,7 +94,7 @@ public class MultipartFileTests {
@Bean
public Function<MultipartFile, String> uppercase() {
return value -> {
return value.getOriginalFilename().toUpperCase();
return value.getOriginalFilename().toUpperCase(Locale.ROOT);
};
}
}

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.function.web.mvc;
import java.net.URI;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -210,7 +211,7 @@ public class RoutingFunctionTests {
public Function<Flux<String>, Flux<String>> fluxuppercase() {
return v -> v.map(s -> {
System.out.println(s);
return s.toUpperCase();
return s.toUpperCase(Locale.ROOT);
});
}

View File

@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.function.Function;
import org.apache.commons.logging.Log;
@@ -94,7 +95,7 @@ public class FunctionAutoConfigurationIntegrationTests {
@Bean
public Function<String, String> uppercase() {
return value -> value.toUpperCase();
return value -> value.toUpperCase(Locale.ROOT);
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.function.web.source;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.function.Function;
import org.apache.commons.logging.Log;
@@ -96,7 +97,7 @@ public class FunctionAutoConfigurationWithRetriesIntegrationTests {
@Bean
public Function<String, String> uppercase() {
return value -> value.toUpperCase();
return value -> value.toUpperCase(Locale.ROOT);
}
}