Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent invalid encoding for files blowing up Source.from_file #364

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rspec/support/source.rb
Expand Up @@ -9,7 +9,11 @@ class Source
attr_reader :source, :path

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

Expand Down
8 changes: 8 additions & 0 deletions 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