Skip to content

Commit

Permalink
Set Locale.ROOT when use String.toLowerCase (#9215)
Browse files Browse the repository at this point in the history
(cherry picked from commit aa7ac0b)
  • Loading branch information
basil authored Apr 30, 2024
1 parent 179ac7a commit 7bbeba4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1435,13 +1435,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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/search/FixedSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -61,7 +62,7 @@ public void suggest(String token, List<SearchItem> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(':');
Expand Down

0 comments on commit 7bbeba4

Please sign in to comment.