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

Handle empty string param in method helper #1415

Merged
merged 1 commit into from
Dec 23, 2021

Conversation

jamuc
Copy link

@jamuc jamuc commented Dec 8, 2021

Description

Hi, I'm using YARD in combination with yard-cucumber to document a company internal GEM. When I ran YARD I got a nil pointer exception

1) YARD::Templates::Helpers::MethodHelper#format_constant when a empty string is passed as param
     Failure/Error: sp = value.split("\n").last[/^(\s+)/, 1]

     NoMethodError:
       undefined method `[]' for nil:NilClass
     # ./lib/yard/templates/helpers/method_helper.rb:70:in `format_constant'
     # ./spec/templates/helpers/method_helper_spec.rb:115:in `block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:127:in `block (2 levels) in <top (required)>'

The problem is that somewhere an empty string is being passed to MethodHelper#format.

This PR fixes that issue with the most simple solution I could think of. If Array#last returns nil, default to an empty string.
I've also extended the MethodHelper spec to cover this case.

My current environment

  • ruby 3.0.2
  • OS X 12.0.1 Monterey

Completed Tasks

  • I have read the Contributing Guide.
  • The pull request is complete (implemented / written).
  • Git commits have been cleaned up (squash WIP / revert commits).
  • I wrote tests and ran bundle exec rake locally (if code is attached to PR).

Copy link
Owner

@lsegal lsegal left a comment

Choose a reason for hiding this comment

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

LGTM!

@lsegal lsegal merged commit a17f67e into lsegal:main Dec 23, 2021
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.

None yet

2 participants