summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/ruby_dsl.rb11
1 files changed, 10 insertions, 1 deletions
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