Skip to content

Commit

Permalink
Fix 'attach' when passing null byte in the data (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelien-reeves committed May 11, 2021
1 parent c350c6c commit 7907579
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Expand Up @@ -16,9 +16,14 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

### Fixed

- `attach` can now handle null bytes in the data.
([1536](https://github.com/cucumber/cucumber-ruby/pull/1536)
[1529](https://github.com/cucumber/cucumber-ruby/issues/1529)
[aurelien-reeves](https://github.com/aurelien-reeves))

### Changed

- The JSON formatter now reports empty scenarios.
- The JSON formatter now reports empty scenarios.
No status is reported for empty scenarios in the resulting JSON.
No more empty background is reported with empty scenarios.
([1533](https://github.com/cucumber/cucumber-ruby/pull/1533)
Expand Down
2 changes: 2 additions & 0 deletions lib/cucumber/glue/proto_world.rb
Expand Up @@ -95,6 +95,8 @@ def attach(file, media_type = nil)
media_type = MIME::Types.type_for(file).first if media_type.nil?

super(content, media_type.to_s)
rescue StandardError
super
end

# Mark the matched step as pending.
Expand Down
35 changes: 35 additions & 0 deletions spec/cucumber/glue/proto_world_spec.rb
Expand Up @@ -127,6 +127,41 @@ module Glue
end
end
end

describe 'Handling attachments in step definitions' do
extend Cucumber::Formatter::SpecHelperDsl
include Cucumber::Formatter::SpecHelper

before(:each) do
Cucumber::Term::ANSIColor.coloring = false
@out = StringIO.new
@formatter = Cucumber::Formatter::Pretty.new(actual_runtime.configuration.with_options(out_stream: @out, source: false))
run_defined_feature
end

describe 'when attaching data with null byte' do
define_feature <<-FEATURE
Feature: Banana party
Scenario: Monkey eats banana
When some data is attached
FEATURE

define_steps do
When('some data is attached') do
attach("'\x00'attachement", 'text/x.cucumber.log+plain')
end
end

it 'does not report an error' do
expect(@out.string).not_to include 'Error'
end

it 'properly attaches the data' do
expect(@out.string).to include "'\x00'attachement"
end
end
end
end
end
end

0 comments on commit 7907579

Please sign in to comment.