Skip to content

bugfix: Fix potential NME when converting ParameterType to envelope #1789

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mitchgrout
Copy link

Description

Sets source_reference to nil if the parameter type transformer does not provide a valid source location, i.e. is nil.

Fixes #1788

Type of change

Bug fix (non-breaking change which fixes an issue)

Checklist:

Your PR is ready for review once the following checklist is
complete. You can also add some checks if you want to.

  • Tests have been added for any changes to behaviour of the code
  • New and existing tests are passing locally and on CI
  • bundle exec rubocop reports no offenses
  • RDoc comments have been updated
  • CHANGELOG.md has been updated

@mitchgrout
Copy link
Author

@luke-hill relatively straight-forward fix, although I'm not super pleased with the rspec test due to the method of interest being private. I don't think this warrants an update to any of the features since it's an admittedly weird way to declare a ParameterType(), but I can add one if you think it's worth it

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I agree on no source location being provided when a bound method. because it still exists there.

But I've not dug into it in more detail

Also we need to keep the contract up. I might ask how the other flavours deal with it

@@ -30,6 +30,7 @@ refactored to use newer, less procedural ruby_)
- Fixed an issue where a change to one example in compatibility testing wasn't fully adhered to ([luke-hill](https://github.com/luke-hill))
- Fixed Ruby 3.4+ issue where error backtraces weren't being formatted. ([#1771](https://github.com/cucumber/cucumber-ruby/pull/1771) [orien](https://github.com/orien))
- Fix some problematic specs that were leaking state and showcasing an issue on JRuby ([#1783](https://github.com/cucumber/cucumber-ruby/pull/1783) [luke-hill](https://github.com/luke-hill))
- Fixed an issue where NoMethodError could be raised when declaring a parameter-type that used bound methods ([#1789](https://github.com/cucumber/cucumber-ruby/pull/1789))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will conflict soon as I'm about to cut v10. I will happily cut another v10.0.1 soon after if desired

def source_reference_for(transformer)
# #source_location may return nil if no definition was found
# This is the case for transformers created using method(sym) or similar
return nil if transformer.source_location.nil?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% we can do this as it might break the contract we have in messages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the sourceReference field for ParameterType has always been optional:

This is why I opted specifically to omit the entire SourceReference object, rather than providing one with nil interior values

let(:prefer_for_regexp_match) { true }

before do
allow(configuration).to receive_message_chain(:id_generator, :new_id).and_return(id) # rubocop:disable RSpec/MessageChain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to remove inline stuff, I don't mind it being added to the overall directive to be fixed up at a later date or if you can tackle it here that would be good

regular_expressions: [%("[^"]+")],
prefer_for_regular_expression_match: true,
use_for_snippets: false,
source_reference: anything # tested in later cases
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid cop offenses can this be returned as something like :no_op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NoMethodError when method(sym) used for ParameterType.transformer
2 participants