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

Commit 7aa2de0

Browse files
committed
Prevent invalid encoding for files blowing up
1 parent 29f8cd5 commit 7aa2de0

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
@@ -9,7 +9,11 @@ class Source
99
attr_reader :source, :path
1010

1111
def self.from_file(path)
12-
source = File.read(path)
12+
# We must use `binread` here, there is no spec for this behaviour
13+
# as its proven troublesome to replicate within our spec suite, but
14+
# to manually verify run:
15+
# `bundle exec rspec spec/support/source_broken_example`
16+
source = File.binread(path)
1317
new(source, path)
1418
end
1519

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)