Skip to content

Commit

Permalink
[Core] Use Locale.ROOT when transforming case of identifiers
Browse files Browse the repository at this point in the history
Several plugins use lowercased string representations of enum
values. Doing this without an explicit locale results in the
default locale being used. This may lead to surprising errors.

Fixes: cucumber/cucumber-java-skeleton#33
  • Loading branch information
mpkorstanje committed Oct 18, 2018
1 parent e99e102 commit 9346da2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/cucumber/api/HookType.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cucumber.api;

import static java.util.Locale.ROOT;

public enum HookType {
Before, After, BeforeStep, AfterStep;

@Override
public String toString() {
return super.toString().toLowerCase();
return super.toString().toLowerCase(ROOT);
}
}
7 changes: 4 additions & 3 deletions core/src/main/java/cucumber/api/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Comparator;
import java.util.Objects;

import static java.util.Locale.ROOT;
import static java.util.Objects.requireNonNull;

public final class Result {
Expand All @@ -30,15 +31,15 @@ public enum Type {
FAILED;

public static Type fromLowerCaseName(String lowerCaseName) {
return valueOf(lowerCaseName.toUpperCase());
return valueOf(lowerCaseName.toUpperCase(ROOT));
}

public String lowerCaseName() {
return name().toLowerCase();
return name().toLowerCase(ROOT);
}

public String firstLetterCapitalizedName() {
return name().substring(0, 1) + name().substring(1).toLowerCase();
return name().substring(0, 1) + name().substring(1).toLowerCase(ROOT);
}


Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/cucumber/runtime/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Properties;
import java.util.ResourceBundle;

import static java.util.Locale.ROOT;

/**
* Looks up values in the following order:
* <ol>
Expand Down Expand Up @@ -56,8 +58,8 @@ public Env(String bundleName, Properties properties) {
private void put(String key, String string) {
map.put(key, string);
// Support old skool
map.put(key.replace('.', '_').toUpperCase(), string);
map.put(key.replace('_', '.').toLowerCase(), string);
map.put(key.replace('.', '_').toUpperCase(ROOT), string);
map.put(key.replace('_', '.').toLowerCase(ROOT), string);
}

public String get(String key) {
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/cucumber/util/Encoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.Locale.ROOT;

/**
* Utilities for reading the encoding of a file.
*/
Expand Down Expand Up @@ -36,6 +38,6 @@ private static String encoding(String source) {
break;
}
}
return encoding.toUpperCase();
return encoding.toUpperCase(ROOT);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cucumber.runtime.junit;

import static java.util.Locale.ROOT;

public enum NotificationLevel {
SCENARIO,
STEP;

String lowerCaseName() {
return name().toLowerCase();
return name().toLowerCase(ROOT);
}
}

0 comments on commit 9346da2

Please sign in to comment.