From 3b50f4ba41ececd01dcf2e35c4071495f250d609 Mon Sep 17 00:00:00 2001 From: hituzi no sippo Date: Thu, 11 Dec 2025 19:16:17 +0900 Subject: [PATCH] [ruby/rubygems] Support single quotes in mise format ruby version https://github.com/ruby/rubygems/commit/a7d7ab39dd --- lib/bundler/ruby_dsl.rb | 8 ++++---- spec/bundler/bundler/ruby_dsl_spec.rb | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/bundler/ruby_dsl.rb b/lib/bundler/ruby_dsl.rb index db4d5521e5..228904850a 100644 --- a/lib/bundler/ruby_dsl.rb +++ b/lib/bundler/ruby_dsl.rb @@ -42,16 +42,16 @@ module Bundler # 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 /x.match(file_content) $1 else diff --git a/spec/bundler/bundler/ruby_dsl_spec.rb b/spec/bundler/bundler/ruby_dsl_spec.rb index 0d02542fb5..4ef0296695 100644 --- a/spec/bundler/bundler/ruby_dsl_spec.rb +++ b/spec/bundler/bundler/ruby_dsl_spec.rb @@ -178,11 +178,21 @@ RSpec.describe Bundler::RubyDsl do 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