From 57a73404c26c81cadcac3ffce233863cb6c859f5 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Fri, 14 Jul 2023 10:07:45 -0500 Subject: [PATCH] skip parsing gemfile when not parseable (#684) Fixes #683 --- src/plugins/core/ruby.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/plugins/core/ruby.rs b/src/plugins/core/ruby.rs index 3c0b108277..d6a326186d 100644 --- a/src/plugins/core/ruby.rs +++ b/src/plugins/core/ruby.rs @@ -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)] @@ -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 + "#}), + "" + ); } }