Skip to content

Commit e41dc82

Browse files
mhlidddevflow.devflow-routing-intake
andauthored
Add Locale.ROOT to ConfigStrings Environment Variable Normalization (#11979)
adding locale.root to toEnvVar force locale for individual test Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent 33c406b commit e41dc82

3 files changed

Lines changed: 37 additions & 15 deletions

File tree

dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/InstrumentationSpecification.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ abstract class InstrumentationSpecification extends DDSpecification implements A
124124
StringBuilder ddEnvVars = new StringBuilder()
125125
for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
126126
if (entry.getKey().toString().startsWith("dd.")) {
127-
ddEnvVars.append(ConfigStrings.systemPropertyNameToEnvironmentVariableName(entry.getKey().toString()))
127+
ddEnvVars.append(ConfigStrings.toEnvVar(entry.getKey().toString()))
128128
.append("=").append(entry.getValue()).append(",")
129129
}
130130
}

utils/config-utils/src/main/java/datadog/trace/util/ConfigStrings.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package datadog.trace.util;
22

3+
import java.util.Locale;
34
import javax.annotation.Nonnull;
45

56
public final class ConfigStrings {
67

78
private ConfigStrings() {}
89

910
public static String toEnvVar(String string) {
10-
return string.replace('.', '_').replace('-', '_').toUpperCase();
11+
return string.replace('.', '_').replace('-', '_').toUpperCase(Locale.ROOT);
1112
}
1213

1314
public static String toEnvVarLowerCase(String string) {
14-
return string.replace('.', '_').replace('-', '_').toLowerCase();
15+
return string.replace('.', '_').replace('-', '_').toLowerCase(Locale.ROOT);
1516
}
1617

1718
/**
@@ -26,18 +27,6 @@ public static String propertyNameToEnvironmentVariableName(final String setting)
2627
return "DD_" + toEnvVar(setting);
2728
}
2829

29-
/**
30-
* Converts the system property name, e.g. 'dd.service.name' into a public environment variable
31-
* name, e.g. `DD_SERVICE_NAME`.
32-
*
33-
* @param setting The system property name, e.g. `dd.service.name`
34-
* @return The public facing environment variable name
35-
*/
36-
@Nonnull
37-
public static String systemPropertyNameToEnvironmentVariableName(final String setting) {
38-
return setting.replace('.', '_').replace('-', '_').toUpperCase();
39-
}
40-
4130
/**
4231
* Converts the property name, e.g. 'service.name' into a public system property name, e.g.
4332
* `dd.service.name`.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package datadog.trace.util;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
6+
import java.util.Locale;
7+
import org.junit.jupiter.api.Test;
8+
9+
class ConfigStringsTest {
10+
11+
/** Dotted capital I (U+0130) that a Turkish-locale {@code toUpperCase()} produces from 'i'. */
12+
private static final char DOTTED_CAPITAL_I = 'İ';
13+
14+
@Test
15+
void toEnvVarUppercasesLowerIToAsciiIOnTurkishLocale() {
16+
// Turkish is the locale where a locale-sensitive toUpperCase() maps 'i' -> 'İ'
17+
// Forcing it as the default locale here proves the conversions are
18+
// locale-independent (pinned to Locale.ROOT) rather than relying on the machine's locale.
19+
Locale previousDefault = Locale.getDefault();
20+
Locale.setDefault(new Locale("tr", "TR"));
21+
try {
22+
String result = ConfigStrings.toEnvVar("dd.profiling.i");
23+
24+
// Must be the plain ASCII 'I' (U+0049), not the Turkish dotted 'İ' (U+0130).
25+
assertEquals("DD_PROFILING_I", result);
26+
assertFalse(
27+
result.indexOf(DOTTED_CAPITAL_I) >= 0,
28+
"env var name must not contain the dotted capital I (U+0130)");
29+
} finally {
30+
Locale.setDefault(previousDefault);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)