Ignore paths with invalid env vars

This commit is contained in:
Denis Isidoro 2021-08-09 10:23:07 -03:00 committed by GitHub
parent 32a3746174
commit c976c9199d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,19 +67,20 @@ fn without_first(string: &str) -> String {
.to_string() .to_string()
} }
fn interpolate_paths(paths: String) -> Result<String> { fn interpolate_paths(paths: String) -> String {
let re = Regex::new(r#"\$\{?[a-zA-Z_][a-zA-Z_0-9]*"#).unwrap(); let re = Regex::new(r#"\$\{?[a-zA-Z_][a-zA-Z_0-9]*"#).unwrap();
let mut newtext = paths.to_string(); let mut newtext = paths.to_string();
for capture in re.captures_iter(&paths) { for capture in re.captures_iter(&paths) {
if let Some(c) = capture.get(0) { if let Some(c) = capture.get(0) {
let varname = c.as_str().replace("$", "").replace("{", "").replace("}", ""); let varname = c.as_str().replace("$", "").replace("{", "").replace("}", "");
let replacement = &env_var::get(&varname)?; if let Ok(replacement) = &env_var::get(&varname) {
newtext = newtext newtext = newtext
.replace(&format!("${}", varname), replacement) .replace(&format!("${}", varname), replacement)
.replace(&format!("${{{}}}", varname), replacement); .replace(&format!("${{{}}}", varname), replacement);
}
} }
} }
Ok(newtext) newtext
} }
fn gen_lists(tag_rules: Option<String>) -> (Option<Vec<String>>, Option<Vec<String>>) { fn gen_lists(tag_rules: Option<String>) -> (Option<Vec<String>>, Option<Vec<String>>) {
@ -142,7 +143,7 @@ impl fetcher::Fetcher for Fetcher {
}; };
let paths = paths.expect("Unable to get paths"); let paths = paths.expect("Unable to get paths");
let interpolated_paths = interpolate_paths(paths)?; let interpolated_paths = interpolate_paths(paths);
let folders = paths_from_path_param(&interpolated_paths); let folders = paths_from_path_param(&interpolated_paths);
let home_regex = Regex::new(r"^~").unwrap(); let home_regex = Regex::new(r"^~").unwrap();