diff --git a/java/src/org/openqa/selenium/Architecture.java b/java/src/org/openqa/selenium/Architecture.java index a4cfdb7087bee..35798b5ed9475 100644 --- a/java/src/org/openqa/selenium/Architecture.java +++ b/java/src/org/openqa/selenium/Architecture.java @@ -17,6 +17,8 @@ package org.openqa.selenium; +import java.util.Locale; + /** * Represents the known architectures used in WebDriver. It attempts to smooth over some of Java's * rough edges when dealing with microprocessor architectures by, for instance, allowing you to @@ -98,7 +100,7 @@ public int getDataModel() { @Override public String toString() { - return name().toLowerCase(); + return name().toLowerCase(Locale.ENGLISH); } /** @@ -121,7 +123,7 @@ public static Architecture getCurrent() { */ public static Architecture extractFromSysProperty(String arch) { if (arch != null) { - arch = arch.toLowerCase(); + arch = arch.toLowerCase(Locale.ENGLISH); } // Some architectures are basically the same even though they have different names. ia32, x86, diff --git a/java/src/org/openqa/selenium/Platform.java b/java/src/org/openqa/selenium/Platform.java index 577aaef2881cc..66f7927eaeb9b 100644 --- a/java/src/org/openqa/selenium/Platform.java +++ b/java/src/org/openqa/selenium/Platform.java @@ -18,6 +18,7 @@ package org.openqa.selenium; import java.util.Arrays; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -414,7 +415,7 @@ public static Platform extractFromSysProperty(String osName) { * @return the most likely platform based on given operating system name and version */ public static Platform extractFromSysProperty(String osName, String osVersion) { - osName = osName.toLowerCase(); + osName = osName.toLowerCase(Locale.ENGLISH); // os.name for android is linux if ("dalvik".equalsIgnoreCase(System.getProperty("java.vm.name"))) { return Platform.ANDROID; @@ -434,7 +435,7 @@ public static Platform extractFromSysProperty(String osName, String osVersion) { if ("".equals(matcher)) { continue; } - matcher = matcher.toLowerCase(); + matcher = matcher.toLowerCase(Locale.ENGLISH); if (os.isExactMatch(osName, matcher)) { return os; } diff --git a/java/src/org/openqa/selenium/Proxy.java b/java/src/org/openqa/selenium/Proxy.java index ca264597802ae..345256444c4a0 100644 --- a/java/src/org/openqa/selenium/Proxy.java +++ b/java/src/org/openqa/selenium/Proxy.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -93,7 +94,8 @@ public Proxy() { public Proxy(Map raw) { Map> setters = new HashMap<>(); setters.put( - PROXY_TYPE, value -> setProxyType(ProxyType.valueOf(((String) value).toUpperCase()))); + PROXY_TYPE, + value -> setProxyType(ProxyType.valueOf(((String) value).toUpperCase(Locale.ENGLISH)))); setters.put(FTP_PROXY, value -> setFtpProxy((String) value)); setters.put(HTTP_PROXY, value -> setHttpProxy((String) value)); setters.put( @@ -448,7 +450,7 @@ public String toString() { case DIRECT: case MANUAL: case SYSTEM: - builder.append(getProxyType().toString().toLowerCase()); + builder.append(getProxyType().toString().toLowerCase(Locale.ENGLISH)); break; case PAC: diff --git a/java/src/org/openqa/selenium/chrome/ChromeDriverService.java b/java/src/org/openqa/selenium/chrome/ChromeDriverService.java index 566ceb7717d16..d6beaa0b69489 100644 --- a/java/src/org/openqa/selenium/chrome/ChromeDriverService.java +++ b/java/src/org/openqa/selenium/chrome/ChromeDriverService.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriverException; @@ -300,7 +301,7 @@ protected List createArgs() { } if (logLevel != null) { - args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase())); + args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase(Locale.ENGLISH))); } if (allowedListIps != null) { args.add(String.format("--allowed-ips=%s", allowedListIps)); diff --git a/java/src/org/openqa/selenium/chromium/ChromiumDriverLogLevel.java b/java/src/org/openqa/selenium/chromium/ChromiumDriverLogLevel.java index 830d4ad01a211..de57b8e917c5c 100644 --- a/java/src/org/openqa/selenium/chromium/ChromiumDriverLogLevel.java +++ b/java/src/org/openqa/selenium/chromium/ChromiumDriverLogLevel.java @@ -17,6 +17,7 @@ package org.openqa.selenium.chromium; +import java.util.Locale; import java.util.Map; import java.util.logging.Level; @@ -46,7 +47,7 @@ public enum ChromiumDriverLogLevel { @Override public String toString() { - return super.toString().toLowerCase(); + return super.toString().toLowerCase(Locale.ENGLISH); } public static ChromiumDriverLogLevel fromString(String text) { diff --git a/java/src/org/openqa/selenium/devtools/NetworkInterceptor.java b/java/src/org/openqa/selenium/devtools/NetworkInterceptor.java index d3777136b3780..427e225ac339b 100644 --- a/java/src/org/openqa/selenium/devtools/NetworkInterceptor.java +++ b/java/src/org/openqa/selenium/devtools/NetworkInterceptor.java @@ -19,6 +19,7 @@ import static org.openqa.selenium.remote.http.Contents.utf8String; +import java.util.Locale; import java.util.Map; import java.util.Optional; import org.openqa.selenium.WebDriver; @@ -105,7 +106,7 @@ public void close() { protected HttpMethod convertFromCdpHttpMethod(String method) { Require.nonNull("HTTP Method", method); try { - return HttpMethod.valueOf(method.toUpperCase()); + return HttpMethod.valueOf(method.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { // Spam in a reasonable value return HttpMethod.GET; diff --git a/java/src/org/openqa/selenium/devtools/idealized/Network.java b/java/src/org/openqa/selenium/devtools/idealized/Network.java index ec36b5d40d5d0..949811311a6be 100644 --- a/java/src/org/openqa/selenium/devtools/idealized/Network.java +++ b/java/src/org/openqa/selenium/devtools/idealized/Network.java @@ -26,6 +26,7 @@ import java.util.Base64; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.concurrent.CancellationException; @@ -300,7 +301,7 @@ protected Optional getAuthCredentials(URI uri) { protected HttpMethod convertFromCdpHttpMethod(String method) { Require.nonNull("HTTP Method", method); try { - return HttpMethod.valueOf(method.toUpperCase()); + return HttpMethod.valueOf(method.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { // Spam in a reasonable value return HttpMethod.GET; diff --git a/java/src/org/openqa/selenium/edge/EdgeDriverService.java b/java/src/org/openqa/selenium/edge/EdgeDriverService.java index a089f93055519..0e3c252087882 100644 --- a/java/src/org/openqa/selenium/edge/EdgeDriverService.java +++ b/java/src/org/openqa/selenium/edge/EdgeDriverService.java @@ -27,6 +27,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Map; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriverException; @@ -294,7 +295,7 @@ protected List createArgs() { } if (logLevel != null) { - args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase())); + args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase(Locale.ENGLISH))); } if (Boolean.TRUE.equals(silent)) { args.add("--silent"); diff --git a/java/src/org/openqa/selenium/firefox/FirefoxBinary.java b/java/src/org/openqa/selenium/firefox/FirefoxBinary.java index 436ebefd0a7b6..8c902c1490b65 100644 --- a/java/src/org/openqa/selenium/firefox/FirefoxBinary.java +++ b/java/src/org/openqa/selenium/firefox/FirefoxBinary.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -72,7 +73,7 @@ public String toString() { * @return the Channel enum value matching the parameter */ public static Channel fromString(String name) { - final String lcName = name.toLowerCase(); + final String lcName = name.toLowerCase(Locale.ENGLISH); return stream(Channel.values()) .filter(ch -> ch.name.equals(lcName)) .findFirst() diff --git a/java/src/org/openqa/selenium/firefox/FirefoxDriverLogLevel.java b/java/src/org/openqa/selenium/firefox/FirefoxDriverLogLevel.java index b3500dc1909c5..b46e762214b84 100644 --- a/java/src/org/openqa/selenium/firefox/FirefoxDriverLogLevel.java +++ b/java/src/org/openqa/selenium/firefox/FirefoxDriverLogLevel.java @@ -18,6 +18,7 @@ package org.openqa.selenium.firefox; import java.util.Collections; +import java.util.Locale; import java.util.Map; import java.util.logging.Level; @@ -47,7 +48,7 @@ public enum FirefoxDriverLogLevel { @Override public String toString() { - return super.toString().toLowerCase(); + return super.toString().toLowerCase(Locale.ENGLISH); } public static FirefoxDriverLogLevel fromString(String text) { diff --git a/java/src/org/openqa/selenium/grid/config/DescribedOption.java b/java/src/org/openqa/selenium/grid/config/DescribedOption.java index d11a9e71eb677..3e5aa4e25b133 100644 --- a/java/src/org/openqa/selenium/grid/config/DescribedOption.java +++ b/java/src/org/openqa/selenium/grid/config/DescribedOption.java @@ -32,6 +32,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.Optional; import java.util.ServiceLoader; @@ -194,7 +195,7 @@ public int hashCode() { } public String getType(Type type) { - String className = deriveClass(type).getSimpleName().toLowerCase(); + String className = deriveClass(type).getSimpleName().toLowerCase(Locale.ENGLISH); return isCollection(type) ? "list of " + className + "s" : className; } diff --git a/java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java b/java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java index d10767e4b6c35..37c583a259dc2 100644 --- a/java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java +++ b/java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java @@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting; import java.util.Comparator; +import java.util.Locale; import java.util.Set; import org.openqa.selenium.Capabilities; import org.openqa.selenium.grid.config.Config; @@ -67,7 +68,7 @@ public Set selectSlot( @VisibleForTesting long getNumberOfSupportedBrowsers(NodeStatus nodeStatus) { return nodeStatus.getSlots().stream() - .map(slot -> slot.getStereotype().getBrowserName().toLowerCase()) + .map(slot -> slot.getStereotype().getBrowserName().toLowerCase(Locale.ENGLISH)) .distinct() .count(); } diff --git a/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java b/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java index ff8fc6d76667a..0a3fd5d82d0ae 100644 --- a/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java +++ b/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java @@ -36,6 +36,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.ServiceLoader; @@ -582,7 +583,9 @@ private void addSpecificDrivers( Optional>> first = allDrivers.entrySet().stream() - .filter(entry -> drivers.contains(entry.getKey().getDisplayName().toLowerCase())) + .filter( + entry -> + drivers.contains(entry.getKey().getDisplayName().toLowerCase(Locale.ENGLISH))) .findFirst(); if (first.isEmpty()) { @@ -590,8 +593,11 @@ private void addSpecificDrivers( } allDrivers.entrySet().stream() - .filter(entry -> drivers.contains(entry.getKey().getDisplayName().toLowerCase())) - .sorted(Comparator.comparing(entry -> entry.getKey().getDisplayName().toLowerCase())) + .filter( + entry -> drivers.contains(entry.getKey().getDisplayName().toLowerCase(Locale.ENGLISH))) + .sorted( + Comparator.comparing( + entry -> entry.getKey().getDisplayName().toLowerCase(Locale.ENGLISH))) .peek(this::report) .forEach( entry -> { @@ -614,7 +620,8 @@ private Map> discoverDrivers( List driversSM = StreamSupport.stream(ServiceLoader.load(WebDriverInfo.class).spliterator(), false) .filter(WebDriverInfo::isAvailable) - .sorted(Comparator.comparing(info -> info.getDisplayName().toLowerCase())) + .sorted( + Comparator.comparing(info -> info.getDisplayName().toLowerCase(Locale.ENGLISH))) .collect(Collectors.toList()); infos.addAll(driversSM); } else { @@ -625,7 +632,8 @@ private Map> discoverDrivers( List localDrivers = StreamSupport.stream(ServiceLoader.load(WebDriverInfo.class).spliterator(), false) .filter(WebDriverInfo::isPresent) - .sorted(Comparator.comparing(info -> info.getDisplayName().toLowerCase())) + .sorted( + Comparator.comparing(info -> info.getDisplayName().toLowerCase(Locale.ENGLISH))) .collect(Collectors.toList()); infos.addAll(localDrivers); } @@ -708,7 +716,7 @@ public Optional createDriver(Capabilities capabilities) private int getDriverMaxSessions(WebDriverInfo info, int desiredMaxSessions) { // Safari and Safari Technology Preview if (info.getMaximumSimultaneousSessions() == 1 - && SINGLE_SESSION_DRIVERS.contains(info.getDisplayName().toLowerCase())) { + && SINGLE_SESSION_DRIVERS.contains(info.getDisplayName().toLowerCase(Locale.ENGLISH))) { return info.getMaximumSimultaneousSessions(); } boolean overrideMaxSessions = diff --git a/java/src/org/openqa/selenium/grid/node/config/SessionCapabilitiesMutator.java b/java/src/org/openqa/selenium/grid/node/config/SessionCapabilitiesMutator.java index fca93f5035882..79a03e7bcee25 100644 --- a/java/src/org/openqa/selenium/grid/node/config/SessionCapabilitiesMutator.java +++ b/java/src/org/openqa/selenium/grid/node/config/SessionCapabilitiesMutator.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.function.Function; @@ -56,7 +57,7 @@ public Capabilities apply(Capabilities capabilities) { .setCapability(SE_NO_VNC_PORT, slotStereotype.getCapability(SE_NO_VNC_PORT)); } - String browserName = capabilities.getBrowserName().toLowerCase(); + String browserName = capabilities.getBrowserName().toLowerCase(Locale.ENGLISH); if ("internet explorer".equalsIgnoreCase(browserName)) { return new ImmutableCapabilities(removeUnknownExtensionsForIE(capabilities)); @@ -83,7 +84,7 @@ public Capabilities apply(Capabilities capabilities) { Map toReturn = new HashMap<>(slotStereotype.merge(capabilities).asMap()); // Merge browser specific stereotype and capabilities options - switch (browserName.toLowerCase()) { + switch (browserName.toLowerCase(Locale.ENGLISH)) { case "chrome": case "microsoftedge": case "msedge": diff --git a/java/src/org/openqa/selenium/grid/node/k8s/OneShotNode.java b/java/src/org/openqa/selenium/grid/node/k8s/OneShotNode.java index 45887df7da2e2..77cfbb488e1c5 100644 --- a/java/src/org/openqa/selenium/grid/node/k8s/OneShotNode.java +++ b/java/src/org/openqa/selenium/grid/node/k8s/OneShotNode.java @@ -30,6 +30,7 @@ import java.net.URISyntaxException; import java.time.Duration; import java.time.Instant; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.ServiceLoader; @@ -157,7 +158,7 @@ public static Node create(Config config) { .filter( info -> driverName - .map(name -> name.equals(info.getDisplayName().toLowerCase())) + .map(name -> name.equals(info.getDisplayName().toLowerCase(Locale.ENGLISH))) .orElse(true)) .findFirst() .orElseThrow( diff --git a/java/src/org/openqa/selenium/grid/node/relay/RelayOptions.java b/java/src/org/openqa/selenium/grid/node/relay/RelayOptions.java index 34d827ce3f2e0..cc98f23489fea 100644 --- a/java/src/org/openqa/selenium/grid/node/relay/RelayOptions.java +++ b/java/src/org/openqa/selenium/grid/node/relay/RelayOptions.java @@ -29,6 +29,7 @@ import java.time.Duration; import java.util.Collection; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.logging.Logger; @@ -122,7 +123,7 @@ public String getServiceProtocolVersion() { private String normalizeProtocolVersion(String protocolVersion) { // Support input in the form of "http/1.1" or "HTTP/1.1" - return protocolVersion.toUpperCase().replaceAll("/", "_").replaceAll("\\.", "_"); + return protocolVersion.toUpperCase(Locale.ENGLISH).replaceAll("/", "_").replaceAll("\\.", "_"); } // Method being used in SessionSlot diff --git a/java/src/org/openqa/selenium/grid/web/ResourceHandler.java b/java/src/org/openqa/selenium/grid/web/ResourceHandler.java index b51f54ce3635b..99474bc78140f 100644 --- a/java/src/org/openqa/selenium/grid/web/ResourceHandler.java +++ b/java/src/org/openqa/selenium/grid/web/ResourceHandler.java @@ -42,6 +42,7 @@ import java.io.UncheckedIOException; import java.net.MalformedURLException; import java.net.URL; +import java.util.Locale; import java.util.Optional; import java.util.stream.Collectors; import org.openqa.selenium.internal.Require; @@ -134,7 +135,7 @@ private String mediaType(String uri) { String extension = (index == -1 || uri.length() == index) ? "" : uri.substring(index + 1); MediaType type; - switch (extension.toLowerCase()) { + switch (extension.toLowerCase(Locale.ENGLISH)) { case "appcache": type = CACHE_MANIFEST_UTF_8; break; diff --git a/java/src/org/openqa/selenium/grid/web/ReverseProxyHandler.java b/java/src/org/openqa/selenium/grid/web/ReverseProxyHandler.java index 7373e1095c2eb..b6a98bb323992 100644 --- a/java/src/org/openqa/selenium/grid/web/ReverseProxyHandler.java +++ b/java/src/org/openqa/selenium/grid/web/ReverseProxyHandler.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet; import java.io.UncheckedIOException; +import java.util.Locale; import java.util.logging.Logger; import org.openqa.selenium.internal.Require; import org.openqa.selenium.remote.http.HttpClient; @@ -78,7 +79,7 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException { req.forEachHeader( (name, value) -> { - if (IGNORED_REQ_HEADERS.contains(name.toLowerCase())) { + if (IGNORED_REQ_HEADERS.contains(name.toLowerCase(Locale.ENGLISH))) { return; } toUpstream.addHeader(name, value); diff --git a/java/src/org/openqa/selenium/io/FileHandler.java b/java/src/org/openqa/selenium/io/FileHandler.java index b332d8ff78649..8d171649e15e6 100644 --- a/java/src/org/openqa/selenium/io/FileHandler.java +++ b/java/src/org/openqa/selenium/io/FileHandler.java @@ -25,6 +25,7 @@ import java.nio.file.Files; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.Objects; /** Utility methods for common filesystem activities */ @@ -41,9 +42,10 @@ public static void copyResource(File outputDir, Class forClassLoader, String. private static InputStream locateResource(Class forClassLoader, String name) throws IOException { - String arch = Objects.requireNonNull(System.getProperty("os.arch")).toLowerCase() + "/"; + String arch = + Objects.requireNonNull(System.getProperty("os.arch")).toLowerCase(Locale.ENGLISH) + "/"; List alternatives = Arrays.asList(name, "/" + name, arch + name, "/" + arch + name); - if (System.getProperty("os.name").toLowerCase().contains("mac")) { + if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("mac")) { alternatives.add("mac/" + name); alternatives.add("/mac/" + name); } diff --git a/java/src/org/openqa/selenium/json/SimplePropertyDescriptor.java b/java/src/org/openqa/selenium/json/SimplePropertyDescriptor.java index c993a4b73ca98..71247234fbbf8 100644 --- a/java/src/org/openqa/selenium/json/SimplePropertyDescriptor.java +++ b/java/src/org/openqa/selenium/json/SimplePropertyDescriptor.java @@ -19,6 +19,7 @@ import java.lang.reflect.Method; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.function.Function; @@ -127,7 +128,7 @@ public static SimplePropertyDescriptor[] getPropertyDescriptors(Class clazz) } private static String uncapitalize(String s) { - return s.substring(0, 1).toLowerCase() + s.substring(1); + return s.substring(0, 1).toLowerCase(Locale.ENGLISH) + s.substring(1); } private static boolean hasPrefix(String prefix, String methodName) { diff --git a/java/src/org/openqa/selenium/manager/SeleniumManagerOutput.java b/java/src/org/openqa/selenium/manager/SeleniumManagerOutput.java index 1faee3a809729..3c408679819ba 100644 --- a/java/src/org/openqa/selenium/manager/SeleniumManagerOutput.java +++ b/java/src/org/openqa/selenium/manager/SeleniumManagerOutput.java @@ -17,6 +17,7 @@ package org.openqa.selenium.manager; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.logging.Level; import org.openqa.selenium.internal.Require; @@ -75,7 +76,7 @@ private static Log fromJson(JsonInput input) { while (input.hasNext()) { switch (input.nextName()) { case "level": - switch (input.nextString().toLowerCase()) { + switch (input.nextString().toLowerCase(Locale.ENGLISH)) { case "error": case "warn": level = Level.WARNING; diff --git a/java/src/org/openqa/selenium/remote/http/HttpMessage.java b/java/src/org/openqa/selenium/remote/http/HttpMessage.java index 909d7ecf7bd97..13d7de07205df 100644 --- a/java/src/org/openqa/selenium/remote/http/HttpMessage.java +++ b/java/src/org/openqa/selenium/remote/http/HttpMessage.java @@ -28,6 +28,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; @@ -91,7 +92,7 @@ public Iterable getHeaderNames() { */ public Iterable getHeaders(String name) { return Collections.unmodifiableCollection( - headers.getOrDefault(name.toLowerCase(), Collections.emptyList())); + headers.getOrDefault(name.toLowerCase(Locale.ENGLISH), Collections.emptyList())); } /** @@ -101,7 +102,8 @@ public Iterable getHeaders(String name) { * @return the value */ public String getHeader(String name) { - List values = headers.getOrDefault(name.toLowerCase(), Collections.emptyList()); + String lcName = name.toLowerCase(Locale.ENGLISH); + List values = headers.getOrDefault(lcName, Collections.emptyList()); return !values.isEmpty() ? values.get(0) : null; } @@ -114,7 +116,8 @@ public String getHeader(String name) { * @return self */ public M setHeader(String name, String value) { - return removeHeader(name.toLowerCase()).addHeader(name.toLowerCase(), value); + String lcName = name.toLowerCase(Locale.ENGLISH); + return removeHeader(lcName).addHeader(lcName, value); } /** @@ -126,7 +129,9 @@ public M setHeader(String name, String value) { * @return self */ public M addHeader(String name, String value) { - headers.computeIfAbsent(name.toLowerCase(), (n) -> new ArrayList<>()).add(value); + String lcName = name.toLowerCase(Locale.ENGLISH); + List values = headers.computeIfAbsent(lcName, (n) -> new ArrayList<>()); + values.add(value); return self(); } @@ -137,17 +142,17 @@ public M addHeader(String name, String value) { * @return self */ public M removeHeader(String name) { - headers.remove(name.toLowerCase()); + String lcName = name.toLowerCase(Locale.ENGLISH); + headers.remove(lcName); return self(); } public Charset getContentEncoding() { - Charset charset = UTF_8; try { String contentType = getHeader(HttpHeader.ContentType.getName()); if (contentType != null) { return Arrays.stream(contentType.split(";")) - .map((e) -> e.trim().toLowerCase()) + .map((e) -> e.trim().toLowerCase(Locale.ENGLISH)) .filter((e) -> e.startsWith("charset=")) .map((e) -> e.substring(e.indexOf('=') + 1)) .map(Charset::forName) @@ -157,7 +162,7 @@ public Charset getContentEncoding() { } catch (IllegalArgumentException ignored) { // Do nothing. } - return charset; + return UTF_8; } @Deprecated diff --git a/java/src/org/openqa/selenium/remote/http/HttpMethod.java b/java/src/org/openqa/selenium/remote/http/HttpMethod.java index 73ed0f52aa4b8..fc6622ea40d7f 100644 --- a/java/src/org/openqa/selenium/remote/http/HttpMethod.java +++ b/java/src/org/openqa/selenium/remote/http/HttpMethod.java @@ -17,6 +17,8 @@ package org.openqa.selenium.remote.http; +import java.util.Locale; + public enum HttpMethod { DELETE, GET, @@ -34,7 +36,7 @@ public static HttpMethod getHttpMethod(String method) { } try { - return HttpMethod.valueOf(method.toUpperCase()); + return HttpMethod.valueOf(method.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("No enum constant for method: " + method); } diff --git a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java index d0b9f76d41e57..6fe1ef7c9a47c 100644 --- a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java +++ b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java @@ -37,6 +37,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; @@ -544,7 +545,7 @@ public List select(URI uri) { if (proxy == null) { return List.of(); } - if (uri.getScheme().toLowerCase().startsWith("http")) { + if (uri.getScheme().toLowerCase(Locale.ENGLISH).startsWith("http")) { return List.of(proxy); } return List.of(); diff --git a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java index 22d47eda29e19..3491d9c1bbf00 100644 --- a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java +++ b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java @@ -24,6 +24,7 @@ import java.net.http.HttpRequest.BodyPublisher; import java.net.http.HttpRequest.BodyPublishers; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -94,7 +95,7 @@ public java.net.http.HttpRequest createRequest(HttpRequest req, HttpMethod metho req.forEachHeader( (name, value) -> { // This prevents the IllegalArgumentException that states 'restricted header name: ...' - if (IGNORE_HEADERS.contains(name.toLowerCase())) { + if (IGNORE_HEADERS.contains(name.toLowerCase(Locale.ENGLISH))) { return; } builder.header(name, value); diff --git a/java/src/org/openqa/selenium/support/Color.java b/java/src/org/openqa/selenium/support/Color.java index 0c772ab7cd9b8..bb11a5117741b 100644 --- a/java/src/org/openqa/selenium/support/Color.java +++ b/java/src/org/openqa/selenium/support/Color.java @@ -17,6 +17,7 @@ package org.openqa.selenium.support; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -302,7 +303,7 @@ protected Pattern getPattern() { private static class NamedColorConverter extends Converter { @Override public Color getColor(String value) { - return Colors.valueOf(value.toUpperCase()).getColorValue(); + return Colors.valueOf(value.toUpperCase(Locale.ENGLISH)).getColorValue(); } @Override diff --git a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java index bb02186d91057..25b195b1b5068 100644 --- a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java +++ b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.logging.Level; import java.util.logging.Logger; @@ -301,7 +302,7 @@ private void fireAfterEvents( private String createEventMethodName(String prefix, String originalMethodName) { return prefix - + originalMethodName.substring(0, 1).toUpperCase() + + originalMethodName.substring(0, 1).toUpperCase(Locale.ENGLISH) + originalMethodName.substring(1); } diff --git a/java/src/org/openqa/selenium/support/ui/Select.java b/java/src/org/openqa/selenium/support/ui/Select.java index 5f4021b8b172d..264585e5417f6 100644 --- a/java/src/org/openqa/selenium/support/ui/Select.java +++ b/java/src/org/openqa/selenium/support/ui/Select.java @@ -40,7 +40,7 @@ public class Select implements ISelect, WrapsElement { public Select(WebElement element) { String tagName = element.getTagName(); - if (null == tagName || !"select".equals(tagName.toLowerCase())) { + if (!"select".equalsIgnoreCase(tagName)) { throw new UnexpectedTagNameException("select", tagName); } diff --git a/java/test/org/openqa/selenium/testing/drivers/Browser.java b/java/test/org/openqa/selenium/testing/drivers/Browser.java index a75d321bd7ac8..3037087237032 100644 --- a/java/test/org/openqa/selenium/testing/drivers/Browser.java +++ b/java/test/org/openqa/selenium/testing/drivers/Browser.java @@ -21,6 +21,7 @@ import static org.openqa.selenium.remote.CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.logging.Logger; import org.openqa.selenium.Capabilities; @@ -172,7 +173,7 @@ public static Browser detect() { } try { - return Browser.valueOf(browserName.toUpperCase()); + return Browser.valueOf(browserName.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { throw new RuntimeException( String.format("Cannot determine driver from name %s", browserName), e);