diff --git a/lib/sass/gem_package_importer.rb b/lib/sass/gem_package_importer.rb index 11a25149..33c450f0 100644 --- a/lib/sass/gem_package_importer.rb +++ b/lib/sass/gem_package_importer.rb @@ -7,11 +7,11 @@ class GemPackageImporter def find_file_url(url, _canonicalize_context) return unless url.start_with?('pkg:') - library, _, path = url[4..].partition(/[?#]/).first.partition('/') + library, _, path = url[4..].partition(/[#?]/).first.partition('/') gem_dir = Gem::Dependency.new(library).to_spec.gem_dir gem_dir = "/#{gem_dir}" unless gem_dir.start_with?('/') - "file://#{gem_dir.gsub(/[?#%]/, { '?' => '%3F', '#' => '%23', '%' => '%25' })}/#{path}" + "file://#{gem_dir.gsub(/[#%?\\]/, { '#' => '%23', '%' => '%25', '?' => '%3F', '\\' => '%5C' })}/#{path}" rescue Gem::MissingSpecError nil end diff --git a/spec/sass/gem_package_importer_spec.rb b/spec/sass/gem_package_importer_spec.rb index cce9ebd6..9b5782cc 100644 --- a/spec/sass/gem_package_importer_spec.rb +++ b/spec/sass/gem_package_importer_spec.rb @@ -7,10 +7,16 @@ require 'bundler/inline' sandbox do |dir| + bytes = if Gem.win_platform? + [*32..127] - '<>:"/\|?*'.unpack('C*') + else + (1..127) + end + parent_dir = "#{bytes.map(&:chr).join}スタイル" dir.write({ - '_test.scss' => '/* test */', - '_index.scss' => '@use "test";', - 'test.gemspec' => <<~GEMSPEC + "#{parent_dir}/_test.scss" => '/* test */', + "#{parent_dir}/_index.scss" => '@use "test";', + "#{parent_dir}/test.gemspec" => <<~GEMSPEC Gem::Specification.new do |spec| spec.name = 'test' spec.summary = 'test' @@ -22,7 +28,7 @@ }) gemfile do - gem 'test', path: dir.path, require: false + gem 'test', path: dir.path(parent_dir), require: false end example.call