From ad18a54d21e086acac7f4aa94dae635271976244 Mon Sep 17 00:00:00 2001 From: mpkorstanje Date: Thu, 18 Oct 2018 19:45:16 +0200 Subject: [PATCH] [Core] Use Locale.ROOT when transforming case of identifiers 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: https://github.com/cucumber/cucumber-java-skeleton/issues/33 --- core/src/main/java/cucumber/api/HookType.java | 4 +++- core/src/main/java/cucumber/api/Result.java | 7 ++++--- core/src/main/java/cucumber/runtime/Env.java | 6 ++++-- core/src/main/java/cucumber/util/Encoding.java | 4 +++- .../java/cucumber/runtime/junit/NotificationLevel.java | 4 +++- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/cucumber/api/HookType.java b/core/src/main/java/cucumber/api/HookType.java index acd0923678..5d1d2a32c3 100644 --- a/core/src/main/java/cucumber/api/HookType.java +++ b/core/src/main/java/cucumber/api/HookType.java @@ -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); } } diff --git a/core/src/main/java/cucumber/api/Result.java b/core/src/main/java/cucumber/api/Result.java index 7c65ac36c7..de48752b0f 100644 --- a/core/src/main/java/cucumber/api/Result.java +++ b/core/src/main/java/cucumber/api/Result.java @@ -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 { @@ -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); } diff --git a/core/src/main/java/cucumber/runtime/Env.java b/core/src/main/java/cucumber/runtime/Env.java index 60afa48225..81bea903ec 100644 --- a/core/src/main/java/cucumber/runtime/Env.java +++ b/core/src/main/java/cucumber/runtime/Env.java @@ -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: *
    @@ -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) { diff --git a/core/src/main/java/cucumber/util/Encoding.java b/core/src/main/java/cucumber/util/Encoding.java index 15e19b954e..4b954b260a 100644 --- a/core/src/main/java/cucumber/util/Encoding.java +++ b/core/src/main/java/cucumber/util/Encoding.java @@ -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. */ @@ -36,6 +38,6 @@ private static String encoding(String source) { break; } } - return encoding.toUpperCase(); + return encoding.toUpperCase(ROOT); } } diff --git a/junit/src/main/java/cucumber/runtime/junit/NotificationLevel.java b/junit/src/main/java/cucumber/runtime/junit/NotificationLevel.java index 0b527e80d2..43fdbe93c2 100644 --- a/junit/src/main/java/cucumber/runtime/junit/NotificationLevel.java +++ b/junit/src/main/java/cucumber/runtime/junit/NotificationLevel.java @@ -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); } }