From 19e8301ff1bb10393c5c67ebb19c1324de126c93 Mon Sep 17 00:00:00 2001 From: Jonathan Knapp Date: Fri, 10 Apr 2020 12:41:14 -0400 Subject: [PATCH] Fix ruby version to not assume length (#1082) --- src/modules/ruby.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/ruby.rs b/src/modules/ruby.rs index 152a72f0..2980cf5a 100644 --- a/src/modules/ruby.rs +++ b/src/modules/ruby.rs @@ -38,7 +38,10 @@ fn format_ruby_version(ruby_version: &str) -> Option { .split_whitespace() // return "2.6.0p0" .nth(1)? - .get(0..5)?; + // split into ["2.6.0", "0"] + .split('p') + // return "2.6.0" + .next()?; let mut formatted_version = String::with_capacity(version.len() + 1); formatted_version.push('v'); @@ -104,6 +107,10 @@ mod tests { #[test] fn test_format_ruby_version() -> io::Result<()> { + assert_eq!( + format_ruby_version("ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-darwin19.0]"), + Some("v2.1.10".to_string()) + ); assert_eq!( format_ruby_version("ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]"), Some("v2.5.1".to_string())