From e21c40b761becf5be6120c858da2300e26a86b9c Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 5 Feb 2019 20:02:39 +0000 Subject: [PATCH] Prevent invalid encoding for files blowing up --- lib/rspec/support/source.rb | 6 +++++- spec/support/source_broken_example | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 spec/support/source_broken_example diff --git a/lib/rspec/support/source.rb b/lib/rspec/support/source.rb index 8aad27b2d..18dfe9c9a 100644 --- a/lib/rspec/support/source.rb +++ b/lib/rspec/support/source.rb @@ -21,7 +21,11 @@ class << self end def self.from_file(path) - source = File.read(path) + # We must use `binread` here, there is no spec for this behaviour + # as its proven troublesome to replicate within our spec suite, but + # to manually verify run: + # `bundle exec rspec spec/support/source_broken_example` + source = File.binread(path) new(source, path) end diff --git a/spec/support/source_broken_example b/spec/support/source_broken_example new file mode 100644 index 000000000..87568a6bc --- /dev/null +++ b/spec/support/source_broken_example @@ -0,0 +1,8 @@ +Encoding.default_internal = Encoding::BINARY + +describe UndeclaredModule do + # the missing constant can be anything + it 'crashes and does not even parse this' do + 'привет' + end +end