From 8fa1db79bd35d93140b7c1f2d7d58a946840d46f Mon Sep 17 00:00:00 2001 From: Luiz Eduardo Kowalski Date: Tue, 24 Dec 2024 10:39:11 -0300 Subject: [PATCH] [rubygems/rubygems] Expand and comment the regex https://github.com/rubygems/rubygems/commit/0dd0e93bde --- lib/bundler/ruby_dsl.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/bundler/ruby_dsl.rb b/lib/bundler/ruby_dsl.rb index 1fc4981d29..cd88253f46 100644 --- a/lib/bundler/ruby_dsl.rb +++ b/lib/bundler/ruby_dsl.rb @@ -43,7 +43,16 @@ module Bundler def normalize_ruby_file(filename) file_content = Bundler.read_file(gemfile.dirname.join(filename)) # match "ruby-3.2.2", ruby = "3.2.2" or "ruby 3.2.2" capturing version string up to the first space or comment - if /^ruby[\s-]*(?:=\s*)?"?([^\s#"]+)"?/.match(file_content) + if /^ # Start of line + ruby # Literal "ruby" + [\s-]* # Optional whitespace or hyphens (for "ruby-3.2.2" format) + (?:=\s*)? # Optional equals sign with whitespace (for ruby = "3.2.2" format) + "? # Optional opening quote + ( # Start capturing group + [^\s#"]+ # One or more chars that aren't spaces, #, or quotes + ) # End capturing group + "? # Optional closing quote + /x.match(file_content) $1 else file_content.strip