diff --git a/src/util.rs b/src/util.rs index 19e69e0..d18e6a6 100644 --- a/src/util.rs +++ b/src/util.rs @@ -76,12 +76,12 @@ pub fn parse_duration(s: &str) -> Result { } } -/// Replace all env-var references of the format `"something $foo"` in a string +/// Replace all env-var references of the format `"something ${foo}"` in a string /// by the actual env-variables. If the env-var isn't found, will replace the /// reference with an empty string. pub fn replace_env_var_references(input: String) -> String { lazy_static::lazy_static! { - static ref ENV_VAR_PATTERN: regex::Regex = regex::Regex::new(r"\$([^\s]*)").unwrap(); + static ref ENV_VAR_PATTERN: regex::Regex = regex::Regex::new(r"\$\{([^\s]*)\}").unwrap(); } ENV_VAR_PATTERN .replace_all(&input, |var_name: ®ex::Captures| { @@ -89,3 +89,19 @@ pub fn replace_env_var_references(input: String) -> String { }) .into_owned() } + +#[cfg(test)] +mod test { + use super::replace_env_var_references; + use std; + + #[test] + fn test_replace_env_var_references() { + let scss = "$test: ${USER};"; + + assert_eq!( + replace_env_var_references(String::from(scss)), + format!("$test: {};", std::env::var("USER").unwrap_or_default()) + ) + } +}