Skip to content

Commit db7a04d

Browse files
authored
Merge pull request #746 from aussiDavid/bugfix/null-string
ArgumentError (invalid byte sequence in UTF-8) #736
2 parents 5b925fc + cf23b38 commit db7a04d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/apipie/static_dispatcher.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ def initialize(root)
99

1010
def match?(path)
1111
# Replace all null bytes
12-
path = ::Rack::Utils.unescape(path || '').gsub(/\x0/, '')
12+
path = ::Rack::Utils.unescape(path || '')
13+
.encode(Encoding::UTF_8, invalid: :replace, replace: '')
14+
.gsub(/\x0/, '')
1315

1416
full_path = path.empty? ? @root : File.join(@root, path)
1517
paths = "#{full_path}#{ext}"

spec/lib/file_handler_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@
1414
it { expect(file_handler.match? path).to be_falsy }
1515
it { expect { file_handler.match? path }.to_not raise_error }
1616
end
17+
18+
context 'when the path contans an invalid byte sequence in UTF-8' do
19+
let(:path) { "%B6" }
20+
21+
it { expect(file_handler.match? path).to be_falsy }
22+
it { expect { file_handler.match? path }.to_not raise_error }
23+
end
1724
end
1825
end

0 commit comments

Comments
 (0)