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

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 Nov 28, 2024
1 parent c316afd commit dd4880e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rspec/support/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ class Source
# stubbed out within tests.
class File
class << self
[:read, :expand_path].each do |method_name|
[:binread, :read, :expand_path].each do |method_name|
define_method(method_name, &::File.method(method_name))
end
end
end

def self.from_file(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.read(path)
new(source, path)
end
Expand Down
8 changes: 8 additions & 0 deletions spec/support/source_broken_example
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dd4880e

Please sign in to comment.