Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ abstract class InstrumentationSpecification extends DDSpecification implements A
StringBuilder ddEnvVars = new StringBuilder()
for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
if (entry.getKey().toString().startsWith("dd.")) {
ddEnvVars.append(ConfigStrings.systemPropertyNameToEnvironmentVariableName(entry.getKey().toString()))
ddEnvVars.append(ConfigStrings.toEnvVar(entry.getKey().toString()))
.append("=").append(entry.getValue()).append(",")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package datadog.trace.util;

import java.util.Locale;
import javax.annotation.Nonnull;

public final class ConfigStrings {

private ConfigStrings() {}

public static String toEnvVar(String string) {
return string.replace('.', '_').replace('-', '_').toUpperCase();
return string.replace('.', '_').replace('-', '_').toUpperCase(Locale.ROOT);
}

public static String toEnvVarLowerCase(String string) {
return string.replace('.', '_').replace('-', '_').toLowerCase();
return string.replace('.', '_').replace('-', '_').toLowerCase(Locale.ROOT);
}

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

/**
* Converts the system property name, e.g. 'dd.service.name' into a public environment variable
* name, e.g. `DD_SERVICE_NAME`.
*
* @param setting The system property name, e.g. `dd.service.name`
* @return The public facing environment variable name
*/
@Nonnull
public static String systemPropertyNameToEnvironmentVariableName(final String setting) {
return setting.replace('.', '_').replace('-', '_').toUpperCase();
}

/**
* Converts the property name, e.g. 'service.name' into a public system property name, e.g.
* `dd.service.name`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package datadog.trace.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.util.Locale;
import org.junit.jupiter.api.Test;

class ConfigStringsTest {

/** Dotted capital I (U+0130) that a Turkish-locale {@code toUpperCase()} produces from 'i'. */
private static final char DOTTED_CAPITAL_I = 'İ';

@Test
void toEnvVarUppercasesLowerIToAsciiIOnTurkishLocale() {
// Turkish is the locale where a locale-sensitive toUpperCase() maps 'i' -> 'İ'
// Forcing it as the default locale here proves the conversions are
// locale-independent (pinned to Locale.ROOT) rather than relying on the machine's locale.
Locale previousDefault = Locale.getDefault();
Locale.setDefault(new Locale("tr", "TR"));
try {
String result = ConfigStrings.toEnvVar("dd.profiling.i");

// Must be the plain ASCII 'I' (U+0049), not the Turkish dotted 'İ' (U+0130).
assertEquals("DD_PROFILING_I", result);
assertFalse(
result.indexOf(DOTTED_CAPITAL_I) >= 0,
"env var name must not contain the dotted capital I (U+0130)");
} finally {
Locale.setDefault(previousDefault);
}
}
}