mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-04-25 17:25:17 +02:00
GP-6022: Better error reporting when expanding environment variables in
launch.properties
This commit is contained in:
@@ -182,14 +182,23 @@ public class LaunchProperties {
|
||||
*
|
||||
* @param text The string to expand environment variables in
|
||||
* @return The given string, but with set environment variables expanded
|
||||
* @throws ParseException if there was a problem expanding an environment variable
|
||||
*/
|
||||
private static String expandEnvVars(String text) {
|
||||
private static String expandEnvVars(String text) throws ParseException {
|
||||
Map<String, String> envMap = System.getenv();
|
||||
for (Entry<String, String> entry : envMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
text = text.replaceAll("\\$\\{" + key + "\\}", value.replace("\\", "\\\\"));
|
||||
}
|
||||
return text;
|
||||
}
|
||||
for (Entry<String, String> entry : envMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
try {
|
||||
text = text.replaceAll("\\$\\{" + key + "\\}", value.replace("\\", "\\\\"));
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new ParseException(
|
||||
"Error expanding environment variable in %s (env %s=%s) -- %s".formatted(text,
|
||||
key, value, e.getMessage()),
|
||||
0);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user