Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Windows, inline environment variable values case-insensitively #2693

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion platform/util/src/com/intellij/util/EnvironmentUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,10 @@ public static void inlineParentOccurrences(@NotNull Map<String, String> envs) {
private static final Pattern pattern = Pattern.compile("\\$(.*?)\\$");

public static void inlineParentOccurrences(@NotNull Map<String, String> envs, @NotNull Map<String, String> parentEnv) {
LinkedHashMap<String, String> lookup = new LinkedHashMap<>(envs);
// On Windows, names of environment variables are case-insensitive. On UNIX, names are case-sensitive.
Comparator<String> keyComparator = SystemInfoRt.isWindows ? String.CASE_INSENSITIVE_ORDER : Comparator.naturalOrder();
Map<String, String> lookup = new TreeMap<>(keyComparator);
lookup.putAll(envs);
lookup.putAll(parentEnv);
for (Map.Entry<String, String> entry : envs.entrySet()) {
String key = entry.getKey();
Expand Down
10 changes: 10 additions & 0 deletions platform/util/testSrc/com/intellij/util/EnvironmentUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ public void testTransitive() {
assertEquals("/hey", list.get(2));
}

@Test
public void testWindowsCaseInsensitive() {
assumeWindows();

List<String> list = substitute("FIRST=$foo$;SECOND=$FOO$;THIRD=$fOo$", "FOo=/hey");
assertEquals("/hey", list.get(0));
assertEquals("/hey", list.get(1));
assertEquals("/hey", list.get(2));
}

private static List<String> substitute(String environment, String parent) {
Map<String, String> env = EnvVariablesTable.parseEnvsFromText(environment);
Map<String, String> parentEnv = EnvVariablesTable.parseEnvsFromText(parent);
Expand Down