Skip to content

Commit

Permalink
skip parsing gemfile when not parseable (#684)
Browse files Browse the repository at this point in the history
Fixes #683
  • Loading branch information
jdx authored Jul 14, 2023
1 parent 2be8c64 commit 57a7340
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/plugins/core/ruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,14 @@ fn parse_gemfile(body: &str) -> String {
.replace_all(&v, "$1")
.to_string();
let v = regex!(r#"^[^0-9]"#).replace_all(&v, "").to_string();
regex!(r#"(.*)__ENGINE__(.*)"#)
let v = regex!(r#"(.*)__ENGINE__(.*)"#)
.replace_all(&v, "$2-$1")
.to_string()
.to_string();
// make sure it's like "ruby-3.0.0" or "3.0.0"
if !regex!(r#"^(\w+-)?([0-9])(\.[0-9])*$"#).is_match(&v) {
return "".to_string();
}
v
}

#[cfg(test)]
Expand Down Expand Up @@ -436,5 +441,12 @@ mod tests {
"#}),
"jruby-1.6.7"
);
assert_eq!(
parse_gemfile(indoc! {r#"
source "https://rubygems.org"
ruby File.read(File.expand_path(".ruby-version", __dir__)).strip
"#}),
""
);
}
}

0 comments on commit 57a7340

Please sign in to comment.