From aa7ac0b6341b6a76823ebbef7fc8c8926683c471 Mon Sep 17 00:00:00 2001 From: Bob Du Date: Thu, 18 Apr 2024 20:49:03 +0800 Subject: [PATCH] Set Locale.ROOT when use String.toLowerCase (#9162) Signed-off-by: Bob Du --- core/src/main/java/hudson/PluginManager.java | 8 ++++---- .../main/java/hudson/model/AutoCompletionCandidates.java | 3 ++- core/src/main/java/hudson/search/FixedSet.java | 3 ++- .../main/java/jenkins/security/BasicHeaderProcessor.java | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index 0aeebaf52f3f..1fd5358454a6 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -1443,13 +1443,13 @@ public HttpResponse doPluginsSearch(@QueryParameter String query, @QueryParamete if (query == null || query.isBlank()) { return true; } - return (plugin.name != null && plugin.name.toLowerCase().contains(query.toLowerCase())) || - (plugin.title != null && plugin.title.toLowerCase().contains(query.toLowerCase())) || - (plugin.excerpt != null && plugin.excerpt.toLowerCase().contains(query.toLowerCase())) || + return (plugin.name != null && plugin.name.toLowerCase(Locale.ROOT).contains(query.toLowerCase(Locale.ROOT))) || + (plugin.title != null && plugin.title.toLowerCase(Locale.ROOT).contains(query.toLowerCase(Locale.ROOT))) || + (plugin.excerpt != null && plugin.excerpt.toLowerCase(Locale.ROOT).contains(query.toLowerCase(Locale.ROOT))) || plugin.hasCategory(query) || plugin.getCategoriesStream() .map(UpdateCenter::getCategoryDisplayName) - .anyMatch(category -> category != null && category.toLowerCase().contains(query.toLowerCase())) || + .anyMatch(category -> category != null && category.toLowerCase(Locale.ROOT).contains(query.toLowerCase(Locale.ROOT))) || plugin.hasWarnings() && query.equalsIgnoreCase("warning:"); }) .limit(Math.max(limit - plugins.size(), 1)) diff --git a/core/src/main/java/hudson/model/AutoCompletionCandidates.java b/core/src/main/java/hudson/model/AutoCompletionCandidates.java index 4e58860ceb89..d2f5f17c255f 100644 --- a/core/src/main/java/hudson/model/AutoCompletionCandidates.java +++ b/core/src/main/java/hudson/model/AutoCompletionCandidates.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; import javax.servlet.ServletException; import jenkins.model.Jenkins; import org.kohsuke.stapler.HttpResponse; @@ -172,6 +173,6 @@ private String contextualNameOf(Item i) { } private static boolean startsWithImpl(String str, String prefix, boolean ignoreCase) { - return ignoreCase ? str.toLowerCase().startsWith(prefix.toLowerCase()) : str.startsWith(prefix); + return ignoreCase ? str.toLowerCase(Locale.ROOT).startsWith(prefix.toLowerCase(Locale.ROOT)) : str.startsWith(prefix); } } diff --git a/core/src/main/java/hudson/search/FixedSet.java b/core/src/main/java/hudson/search/FixedSet.java index 3c3819f03bcb..f77e20623542 100644 --- a/core/src/main/java/hudson/search/FixedSet.java +++ b/core/src/main/java/hudson/search/FixedSet.java @@ -27,6 +27,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Locale; /** * Set of {@link SearchItem}s that are statically known upfront. @@ -61,7 +62,7 @@ public void suggest(String token, List result) { boolean caseInsensitive = UserSearchProperty.isCaseInsensitive(); for (SearchItem i : items) { String name = i.getSearchName(); - if (name != null && (name.contains(token) || (caseInsensitive && name.toLowerCase().contains(token.toLowerCase())))) { + if (name != null && (name.contains(token) || (caseInsensitive && name.toLowerCase(Locale.ROOT).contains(token.toLowerCase(Locale.ROOT))))) { result.add(i); } } diff --git a/core/src/main/java/jenkins/security/BasicHeaderProcessor.java b/core/src/main/java/jenkins/security/BasicHeaderProcessor.java index 18ea7b5174c0..45b5eb0c70a2 100644 --- a/core/src/main/java/jenkins/security/BasicHeaderProcessor.java +++ b/core/src/main/java/jenkins/security/BasicHeaderProcessor.java @@ -9,6 +9,7 @@ import hudson.util.Scrambler; import java.io.IOException; import java.util.List; +import java.util.Locale; import java.util.logging.Logger; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -64,7 +65,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha HttpServletResponse rsp = (HttpServletResponse) response; String authorization = req.getHeader("Authorization"); - if (authorization != null && authorization.toLowerCase().startsWith("Basic ".toLowerCase())) { + if (authorization != null && authorization.toLowerCase(Locale.ROOT).startsWith("Basic ".toLowerCase(Locale.ROOT))) { // authenticate the user String uidpassword = Scrambler.descramble(authorization.substring(6)); int idx = uidpassword.indexOf(':');