Skip to content

Commit f3bdea7

Browse files
committed
Test Sass::GemPackageImporter with path containing special characters
1 parent 94e8572 commit f3bdea7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/sass/gem_package_importer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ class GemPackageImporter
77
def find_file_url(url, _canonicalize_context)
88
return unless url.start_with?('pkg:')
99

10-
library, _, path = url[4..].partition(/[?#]/).first.partition('/')
10+
library, _, path = url[4..].partition(/[#?]/).first.partition('/')
1111
gem_dir = Gem::Dependency.new(library).to_spec.gem_dir
1212
gem_dir = "/#{gem_dir}" unless gem_dir.start_with?('/')
1313

14-
"file://#{gem_dir.gsub(/[?#%]/, { '?' => '%3F', '#' => '%23', '%' => '%25' })}/#{path}"
14+
"file://#{gem_dir.gsub(/[#%?\\]/, { '#' => '%23', '%' => '%25', '?' => '%3F', '\\' => '%5C' })}/#{path}"
1515
rescue Gem::MissingSpecError
1616
nil
1717
end

spec/sass/gem_package_importer_spec.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
require 'bundler/inline'
88

99
sandbox do |dir|
10+
bytes = if Gem.win_platform?
11+
[*32..127] - '<>:"/\|?*'.unpack('C*')
12+
else
13+
(1..127)
14+
end
15+
parent_dir = "#{bytes.map(&:chr).join}スタイル"
1016
dir.write({
11-
'_test.scss' => '/* test */',
12-
'_index.scss' => '@use "test";',
13-
'test.gemspec' => <<~GEMSPEC
17+
"#{parent_dir}/_test.scss" => '/* test */',
18+
"#{parent_dir}/_index.scss" => '@use "test";',
19+
"#{parent_dir}/test.gemspec" => <<~GEMSPEC
1420
Gem::Specification.new do |spec|
1521
spec.name = 'test'
1622
spec.summary = 'test'
@@ -22,7 +28,7 @@
2228
})
2329

2430
gemfile do
25-
gem 'test', path: dir.path, require: false
31+
gem 'test', path: dir.path(parent_dir), require: false
2632
end
2733

2834
example.call

0 commit comments

Comments
 (0)