Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bundler/lib/bundler/ruby_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ def ruby(*ruby_version)
# Loads the file relative to the dirname of the Gemfile itself.
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
# match "ruby-3.2.2", ruby = "3.2.2", ruby = '3.2.2' or "ruby 3.2.2" capturing version string up to the first space or comment
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
["']? # Optional opening quote
( # Start capturing group
[^\s#"]+ # One or more chars that aren't spaces, #, or quotes
[^\s#"']+ # One or more chars that aren't spaces, #, or quotes
) # End capturing group
"? # Optional closing quote
["']? # Optional closing quote
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reject "3.2.2' (quote mismatch)?

/x.match(file_content)
$1
else
Expand Down
14 changes: 12 additions & 2 deletions bundler/spec/bundler/ruby_dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,21 @@ class MockDSL
let(:file_content) do
<<~TOML
[tools]
ruby = "#{version}"
ruby = #{quote}#{version}#{quote}
TOML
end

it_behaves_like "it stores the ruby version"
context "with double quotes" do
let(:quote) { '"' }

it_behaves_like "it stores the ruby version"
end

context "with single quotes" do
let(:quote) { "'" }

it_behaves_like "it stores the ruby version"
end
end

context "with a .tool-versions file format" do
Expand Down