From 973ba24a4976ceaffbb01b657a82befba24fad20 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 5 Feb 2019 20:02:39 +0000 Subject: [PATCH 1/2] Prevent invalid encoding for files blowing up --- lib/rspec/support/source.rb | 14 +++++++++++--- spec/support/source_broken_example | 8 ++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 spec/support/source_broken_example diff --git a/lib/rspec/support/source.rb b/lib/rspec/support/source.rb index 8aad27b2d..68fc57ab0 100644 --- a/lib/rspec/support/source.rb +++ b/lib/rspec/support/source.rb @@ -14,14 +14,22 @@ class Source # stubbed out within tests. class File class << self - [:read, :expand_path].each do |method_name| - define_method(method_name, &::File.method(method_name)) + define_method(:expand_path, &::File.method(:expand_path)) + + if RUBY_VERSION.to_f > 1.9 + define_method(:binread, &::File.method(:binread)) + else + define_method(:binread, &::File.method(:read)) end end 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 From adafd70a9f6c42cc6d0f62e5f5891b33997159db Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Fri, 29 Nov 2024 00:12:06 +0000 Subject: [PATCH 2/2] Switch legacy builds to manual git --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8fd5baa7..47bd831cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -133,7 +133,12 @@ jobs: JRUBY_OPTS: ${{ matrix.container.jruby_opts || '--dev' }} NO_COVERAGE: true steps: - - uses: actions/checkout@v3 + - run: git config --global --add safe.directory $GITHUB_WORKSPACE + - run: git init $GITHUB_WORKSPACE + - run: git remote add origin https://github.com/rspec/rspec-support + - run: git config --local gc.auto 0 + - run: git fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +$GITHUB_SHA:$GITHUB_REF + - run: git checkout --progress --force $GITHUB_REF - run: ${{ matrix.container.pre }} - run: script/legacy_setup.sh - run: ${{ matrix.container.post }}