Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit dd4880e

Browse files
committed
Prevent invalid encoding for files blowing up
1 parent c316afd commit dd4880e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/rspec/support/source.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ class Source
1414
# stubbed out within tests.
1515
class File
1616
class << self
17-
[:read, :expand_path].each do |method_name|
17+
[:binread, :read, :expand_path].each do |method_name|
1818
define_method(method_name, &::File.method(method_name))
1919
end
2020
end
2121
end
2222

2323
def self.from_file(path)
24+
# We must use `binread` here, there is no spec for this behaviour
25+
# as its proven troublesome to replicate within our spec suite, but
26+
# to manually verify run:
27+
# `bundle exec rspec spec/support/source_broken_example`
2428
source = File.read(path)
2529
new(source, path)
2630
end

spec/support/source_broken_example

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Encoding.default_internal = Encoding::BINARY
2+
3+
describe UndeclaredModule do
4+
# the missing constant can be anything
5+
it 'crashes and does not even parse this' do
6+
'привет'
7+
end
8+
end

0 commit comments

Comments
 (0)