Skip to content

Commit

Permalink
Prevent invalid encoding for files blowing up
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Feb 5, 2019
1 parent 29f8cd5 commit b5f1cda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rspec/support/source.rb
Expand Up @@ -11,6 +11,11 @@ class Source
def self.from_file(path)
source = File.read(path)
new(source, path)
# There is no spec for this behaviour as its proven troublesome to
# replicate within our spec suite, to manually verify run
# `bundle exec rspec spec/support/source_spec.broken_example`
rescue Encoding::UndefinedConversionError
new("", path)
end

if String.method_defined?(:encoding)
Expand Down
8 changes: 8 additions & 0 deletions spec/support/source_spec.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
header = 'привет'
end
end

0 comments on commit b5f1cda

Please sign in to comment.