Skip to content

Commit 8fa1db7

Browse files
luizkowalskimatzbot
authored andcommitted
[rubygems/rubygems] Expand and comment the regex
ruby/rubygems@0dd0e93bde
1 parent 6e46b9b commit 8fa1db7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/bundler/ruby_dsl.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ def ruby(*ruby_version)
4343
def normalize_ruby_file(filename)
4444
file_content = Bundler.read_file(gemfile.dirname.join(filename))
4545
# match "ruby-3.2.2", ruby = "3.2.2" or "ruby 3.2.2" capturing version string up to the first space or comment
46-
if /^ruby[\s-]*(?:=\s*)?"?([^\s#"]+)"?/.match(file_content)
46+
if /^ # Start of line
47+
ruby # Literal "ruby"
48+
[\s-]* # Optional whitespace or hyphens (for "ruby-3.2.2" format)
49+
(?:=\s*)? # Optional equals sign with whitespace (for ruby = "3.2.2" format)
50+
"? # Optional opening quote
51+
( # Start capturing group
52+
[^\s#"]+ # One or more chars that aren't spaces, #, or quotes
53+
) # End capturing group
54+
"? # Optional closing quote
55+
/x.match(file_content)
4756
$1
4857
else
4958
file_content.strip

0 commit comments

Comments
 (0)