Skip to content

Commit 52dccac

Browse files
idodeclareVladimir Kotal
authored andcommitted
Fix casing issues
- Fix "README" matching. - Review to[Lower,Upper]Case w.r.t. Locale. All reviewed cases except Locale.English in Repository were not dependent on either US, English, or Default locale; and would be properly specified as ROOT. Fixes #1768 for Turkish. - Use String toLowerCase and not Character toLowerCase in PathTokenizer for context-sensitive and 1:M character mappings.
1 parent 99b7d3f commit 52dccac

36 files changed

+191
-87
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,7 @@ public static FileAnalyzerFactory find(String file) {
866866

867867
// Try matching the prefix.
868868
if (dotpos > 0) {
869-
factory
870-
= pre.get(path.substring(0, dotpos).toUpperCase(Locale.getDefault()));
869+
factory = pre.get(path.substring(0, dotpos).toUpperCase(Locale.ROOT));
871870
if (factory != null) {
872871
if (LOGGER.isLoggable(Level.FINER)) {
873872
LOGGER.log(Level.FINER, "{0}: chosen by prefix: {1}",
@@ -881,8 +880,7 @@ public static FileAnalyzerFactory find(String file) {
881880
// Now try matching the suffix. We kind of consider this order (first
882881
// prefix then suffix) to be workable although for sure there can be
883882
// cases when this does not work.
884-
factory
885-
= ext.get(path.substring(dotpos + 1).toUpperCase(Locale.getDefault()));
883+
factory = ext.get(path.substring(dotpos + 1).toUpperCase(Locale.ROOT));
886884
if (factory != null) {
887885
if (LOGGER.isLoggable(Level.FINER)) {
888886
LOGGER.log(Level.FINER, "{0}: chosen by suffix: {1}",
@@ -894,7 +892,7 @@ public static FileAnalyzerFactory find(String file) {
894892
}
895893

896894
// file doesn't have any of the prefix or extensions we know, try full match
897-
return FILE_NAMES.get(path.toUpperCase(Locale.getDefault()));
895+
return FILE_NAMES.get(path.toUpperCase(Locale.ROOT));
898896
}
899897

900898
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/FileAnalyzer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.Reader;
2929
import java.io.StringReader;
3030
import java.io.Writer;
31+
import java.util.Locale;
3132
import java.util.logging.Level;
3233
import java.util.logging.Logger;
3334

@@ -230,14 +231,14 @@ protected FileAnalyzer(FileAnalyzerFactory factory,
230231
* @return Normalized name of the analyzer.
231232
*/
232233
public String getFileTypeName() {
233-
String name = this.getClass().getSimpleName().toLowerCase();
234+
String name = this.getClass().getSimpleName().toLowerCase(Locale.ROOT);
234235
String suffix = "analyzer";
235236

236237
if (name.endsWith(suffix)) {
237238
return name.substring(0, name.length() - suffix.length());
238239
}
239240

240-
return name.toLowerCase();
241+
return name;
241242
}
242243

243244
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/JFlexSymbolMatcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package org.opengrok.indexer.analysis;
2525

26+
import java.util.Locale;
2627
import java.util.Set;
2728
import java.util.regex.Pattern;
2829
import org.opengrok.indexer.util.StringUtils;
@@ -449,7 +450,7 @@ protected boolean onFilteredSymbolMatched(String str, int start,
449450
Set<String> keywords, boolean caseSensitive) {
450451

451452
if (keywords != null) {
452-
String check = caseSensitive ? str : str.toLowerCase();
453+
String check = caseSensitive ? str : str.toLowerCase(Locale.ROOT);
453454
if (keywords.contains(check)) {
454455
onKeywordMatched(str, start);
455456
return false;

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/JFlexXrefUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/*
2121
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright 2011 Jens Elkner.
23-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2424
*/
2525

2626
package org.opengrok.indexer.analysis;
@@ -30,6 +30,7 @@
3030
import java.util.Comparator;
3131
import java.util.HashMap;
3232
import java.util.List;
33+
import java.util.Locale;
3334
import java.util.Map;
3435
import java.util.Set;
3536
import java.util.SortedSet;
@@ -252,7 +253,7 @@ public static boolean writeSymbol(Writer out, Definitions defs,
252253
String[] strs = new String[1];
253254
strs[0] = "";
254255

255-
String check = caseSensitive ? symbol : symbol.toLowerCase();
256+
String check = caseSensitive ? symbol : symbol.toLowerCase(Locale.ROOT);
256257
if (isKeyword || (keywords != null && keywords.contains( check ))) {
257258
// This is a keyword, so we don't create a link.
258259
out.append("<b>");

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/PathTokenizer.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
/*
2121
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.analysis;
2425

2526
import java.io.IOException;
2627
import java.util.Arrays;
28+
import java.util.Locale;
2729
import org.apache.lucene.analysis.Tokenizer;
2830
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
2931
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
@@ -90,14 +92,24 @@ public final boolean incrementToken() throws IOException {
9092
if (i >= buf.length) {
9193
buf = Arrays.copyOf(buf, buf.length * 2);
9294
}
93-
buf[i++] = Character.toLowerCase((char) c);
95+
/**
96+
* "In general, String.toLowerCase(Locale) should be used to map
97+
* characters to lowercase. String case mapping methods have several
98+
* benefits over Character case mapping methods. String case mapping
99+
* methods can perform locale-sensitive mappings, context-sensitive
100+
* mappings, and 1:M character mappings, whereas the Character case
101+
* mapping methods cannot." See below.
102+
*/
103+
buf[i++] = (char)c;
94104
c = input.read();
95105
charsRead++;
96106
} while (c != delimiter && c != cdot && !Character.isWhitespace(c) && c != -1);
97107
if (c == cdot) {
98108
dot = true;
99109
}
100-
termAtt.copyBuffer(buf, 0, i);
110+
String bufLcase = String.valueOf(buf, 0, i).toLowerCase(Locale.ROOT);
111+
i = bufLcase.length();
112+
termAtt.append(bufLcase);
101113
termAtt.setLength(i);
102114
offsetAtt.setOffset(correctOffset(startPosition), correctOffset(startPosition + i));
103115
startPosition = startPosition + i + 1;

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/sql/Consts.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.analysis.sql;
2425

@@ -58,7 +59,7 @@ private static void populateKeywordSet(Set<String> set, String file)
5859
Consts.class.getResourceAsStream(file), StandardCharsets.UTF_8))) {
5960
while ((line = reader.readLine()) != null) {
6061
line=line.trim();
61-
lline = line.toLowerCase(Locale.US);
62+
lline = line.toLowerCase(Locale.ROOT);
6263
if (line.charAt(0) != '#') {
6364
set.add(line);
6465
set.add(lline);

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/sql/PLSQLConsts.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.analysis.sql;
2425

@@ -59,7 +60,7 @@ private static void populateKeywordSet(Set<String> set, String file)
5960
Consts.class.getResourceAsStream(file), StandardCharsets.UTF_8))) {
6061
while ((line = reader.readLine()) != null) {
6162
line=line.trim();
62-
lline = line.toLowerCase(Locale.US);
63+
lline = line.toLowerCase(Locale.ROOT);
6364
if (line.charAt(0) != '#') {
6465
set.add(line);
6566
set.add(lline);

opengrok-indexer/src/main/java/org/opengrok/indexer/authorization/AuthControlFlag.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919

2020
/*
2121
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.authorization;
2425

2526
import java.util.Arrays;
27+
import java.util.Locale;
2628
import java.util.stream.Collectors;
2729

2830
/**
@@ -87,7 +89,7 @@ public boolean isSufficient() {
8789
*/
8890
public static AuthControlFlag get(String flag) throws IllegalArgumentException {
8991
try {
90-
return AuthControlFlag.valueOf(flag.toUpperCase());
92+
return AuthControlFlag.valueOf(flag.toUpperCase(Locale.ROOT));
9193
} catch (IllegalArgumentException ex) {
9294
// flag does not exist -> add some more info about which flags do exist
9395
throw new IllegalArgumentException(

opengrok-indexer/src/main/java/org/opengrok/indexer/authorization/AuthorizationEntity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919

2020
/*
2121
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.authorization;
2425

2526
import java.io.Serializable;
27+
import java.util.Locale;
2628
import java.util.Map;
2729
import java.util.Map.Entry;
2830
import java.util.Set;
@@ -565,7 +567,9 @@ protected String colorToString(String colorElement) {
565567
*/
566568
protected String infoToString(String prefix) {
567569
StringBuilder builder = new StringBuilder(40);
568-
builder.append(" ").append(getFlag().toString().toUpperCase()).append(" '").append(getName()).append("'");
570+
String flup = getFlag().toString().toUpperCase(Locale.ROOT);
571+
String nm = getName();
572+
builder.append(" ").append(flup).append(" '").append(nm).append("'");
569573
return builder.toString();
570574
}
571575

opengrok-indexer/src/main/java/org/opengrok/indexer/authorization/AuthorizationPlugin.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
/*
2121
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.authorization;
2425

26+
import java.util.Locale;
2527
import java.util.Map;
2628
import java.util.TreeMap;
2729
import java.util.logging.Level;
@@ -104,7 +106,7 @@ public synchronized void load(Map<String, Object> parameters) {
104106
setFailed();
105107
LOGGER.log(Level.INFO, "[{0}] Plugin \"{1}\" {2} and is {3}.",
106108
new Object[]{
107-
getFlag().toString().toUpperCase(),
109+
getFlag().toString().toUpperCase(Locale.ROOT),
108110
getName(),
109111
hasPlugin() ? "found" : "not found",
110112
isWorking() ? "working" : "failed"});
@@ -125,7 +127,7 @@ public synchronized void load(Map<String, Object> parameters) {
125127

126128
LOGGER.log(Level.INFO, "[{0}] Plugin \"{1}\" {2} and is {3}.",
127129
new Object[]{
128-
getFlag().toString().toUpperCase(),
130+
getFlag().toString().toUpperCase(Locale.ROOT),
129131
getName(),
130132
hasPlugin() ? "found" : "not found",
131133
isWorking() ? "working" : "failed"});

0 commit comments

Comments
 (0)