summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2024-10-31 17:02:12 +0100
committergit <[email protected]>2024-11-04 10:04:40 +0000
commit50dbe19b685047cff7000878b330eee8a3f2583d (patch)
treef36b4986cef888d2bba36c7aa71dd9781942f4b9
parent21af248f920e4f6806b35e40503f8b84f9edd1ec (diff)
[rubygems/rubygems] Fix incompatible encodings error
https://github.com/rubygems/rubygems/commit/d478ec403f
-rw-r--r--lib/bundler/rubygems_ext.rb14
-rw-r--r--lib/rubygems/package/tar_header.rb11
-rw-r--r--lib/rubygems/package/tar_reader/entry.rb6
-rw-r--r--spec/bundler/commands/install_spec.rb29
4 files changed, 55 insertions, 5 deletions
diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb
index 01c725b031..54c016adcc 100644
--- a/lib/bundler/rubygems_ext.rb
+++ b/lib/bundler/rubygems_ext.rb
@@ -433,4 +433,18 @@ module Gem
end
end
end
+
+ unless Gem.rubygems_version >= Gem::Version.new("3.5.23")
+ class Package; end
+ require "rubygems/package/tar_reader"
+ require "rubygems/package/tar_reader/entry"
+
+ module FixFullNameEncoding
+ def full_name
+ super.force_encoding(Encoding::UTF_8)
+ end
+ end
+
+ Package::TarReader::Entry.prepend(FixFullNameEncoding)
+ end
end
diff --git a/lib/rubygems/package/tar_header.rb b/lib/rubygems/package/tar_header.rb
index dd5e835a1e..0ebcbd789d 100644
--- a/lib/rubygems/package/tar_header.rb
+++ b/lib/rubygems/package/tar_header.rb
@@ -228,6 +228,17 @@ class Gem::Package::TarHeader
@checksum = oct calculate_checksum(header), 6
end
+ ##
+ # Header's full name, including prefix
+
+ def full_name
+ if prefix != ""
+ File.join prefix, name
+ else
+ name
+ end
+ end
+
private
def calculate_checksum(header)
diff --git a/lib/rubygems/package/tar_reader/entry.rb b/lib/rubygems/package/tar_reader/entry.rb
index 5e9d9af5c6..f837e86fd6 100644
--- a/lib/rubygems/package/tar_reader/entry.rb
+++ b/lib/rubygems/package/tar_reader/entry.rb
@@ -87,11 +87,7 @@ class Gem::Package::TarReader::Entry
# Full name of the tar entry
def full_name
- if @header.prefix != ""
- File.join @header.prefix, @header.name
- else
- @header.name
- end
+ @header.full_name.force_encoding(Encoding::UTF_8)
rescue ArgumentError => e
raise unless e.message == "string contains null byte"
raise Gem::Package::TarInvalidError,
diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb
index 6cd9964008..6c9e06f3b8 100644
--- a/spec/bundler/commands/install_spec.rb
+++ b/spec/bundler/commands/install_spec.rb
@@ -1218,6 +1218,35 @@ RSpec.describe "bundle install with gem sources" do
end
end
+ describe "when configured path is UTF-8 and a file inside a gem package too" do
+ let(:app_path) do
+ path = tmp("♥")
+ FileUtils.mkdir_p(path)
+ path
+ end
+
+ let(:path) do
+ root.join("vendor/bundle")
+ end
+
+ before do
+ build_repo4 do
+ build_gem "mygem" do |s|
+ s.write "spec/fixtures/_posts/2016-04-01-错误.html"
+ end
+ end
+ end
+
+ it "works" do
+ bundle "config path #{app_path}/vendor/bundle", dir: app_path
+
+ install_gemfile app_path.join("Gemfile"),<<~G, dir: app_path
+ source "https://gem.repo4"
+ gem "mygem", "1.0"
+ G
+ end
+ end
+
context "after installing with --standalone" do
before do
install_gemfile <<-G