Skip to content

Commit 572255b

Browse files
committed
Use toLower/toUpperCase with Locale argument
Closes gh-1790
1 parent 7286da9 commit 572255b

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

etc/checkstyle/checkstyle-suppressions.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
<suppressions>
66
<suppress files=".*" checks="JavadocStyle" />
77
<suppress files="SpringAuthorizationServerVersion\.java" checks="HideUtilityClassConstructor"/>
8+
<suppress files="[\\/]src[\\/]test[\\/]" checks="RegexpSinglelineJava" id="toLowerCaseWithoutLocale"/>
9+
<suppress files="[\\/]src[\\/]test[\\/]" checks="RegexpSinglelineJava" id="toUpperCaseWithoutLocale"/>
810
</suppressions>

etc/checkstyle/checkstyle.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,22 @@
1515
<property name="excludes" value="io.spring.javaformat.checkstyle.check.SpringHeaderCheck" />
1616
<property name="excludes" value="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck" />
1717
</module>
18+
<module name="com.puppycrawl.tools.checkstyle.TreeWalker">
19+
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
20+
<property name="id" value="toLowerCaseWithoutLocale"/>
21+
<property name="format" value="\.toLowerCase\(\)"/>
22+
<property name="maximum" value="0"/>
23+
<property name="message"
24+
value="String.toLowerCase() should be String.toLowerCase(Locale.ROOT) or String.toLowerCase(Locale.ENGLISH)"/>
25+
<property name="ignoreComments" value="true"/>
26+
</module>
27+
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
28+
<property name="id" value="toUpperCaseWithoutLocale"/>
29+
<property name="format" value="\.toUpperCase\(\)"/>
30+
<property name="maximum" value="0"/>
31+
<property name="message"
32+
value="String.toUpperCase() should be String.toUpperCase(Locale.ROOT) or String.toUpperCase(Locale.ENGLISH)"/>
33+
<property name="ignoreComments" value="true"/>
34+
</module>
35+
</module>
1836
</module>

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/JdbcOAuth2AuthorizationService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
2727
import java.util.Collections;
2828
import java.util.HashMap;
2929
import java.util.List;
30+
import java.util.Locale;
3031
import java.util.Map;
3132
import java.util.Set;
3233
import java.util.function.Function;
@@ -416,7 +417,8 @@ private static ColumnMetadata getColumnMetadata(JdbcOperations jdbcOperations, S
416417
// But if it is not enclosed in double quotes,
417418
// the name is converted to uppercase and this uppercase version is stored in
418419
// the database as the case-normal form.
419-
rs = databaseMetaData.getColumns(null, null, TABLE_NAME.toUpperCase(), columnName.toUpperCase());
420+
rs = databaseMetaData.getColumns(null, null, TABLE_NAME.toUpperCase(Locale.ENGLISH),
421+
columnName.toUpperCase(Locale.ENGLISH));
420422
if (rs.next()) {
421423
return rs.getInt("DATA_TYPE");
422424
}

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/authentication/OAuth2EndpointUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717

1818
import java.util.Collections;
1919
import java.util.HashMap;
20+
import java.util.Locale;
2021
import java.util.Map;
2122

2223
import jakarta.servlet.http.HttpServletRequest;
@@ -110,14 +111,14 @@ static void throwError(String errorCode, String parameterName, String errorUri)
110111

111112
static String normalizeUserCode(String userCode) {
112113
Assert.hasText(userCode, "userCode cannot be empty");
113-
StringBuilder sb = new StringBuilder(userCode.toUpperCase().replaceAll("[^A-Z\\d]+", ""));
114+
StringBuilder sb = new StringBuilder(userCode.toUpperCase(Locale.ENGLISH).replaceAll("[^A-Z\\d]+", ""));
114115
Assert.isTrue(sb.length() == 8, "userCode must be exactly 8 alpha/numeric characters");
115116
sb.insert(4, '-');
116117
return sb.toString();
117118
}
118119

119120
static boolean validateUserCode(String userCode) {
120-
return (userCode != null && userCode.toUpperCase().replaceAll("[^A-Z\\d]+", "").length() == 8);
121+
return (userCode != null && userCode.toUpperCase(Locale.ENGLISH).replaceAll("[^A-Z\\d]+", "").length() == 8);
121122
}
122123

123124
}

0 commit comments

Comments
 (0)