Skip to content

Commit

Permalink
Merge pull request #1696 from bcgraham/fix-nb-space-infinite-loop
Browse files Browse the repository at this point in the history
Fix infinite loop in ExcessiveDocstringSpacing
  • Loading branch information
bquorning committed Aug 15, 2023
2 parents e09a701 + a4db148 commit ff30ce1
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

- Fix an infinite loop error when `RSpec/ExcessiveDocstringSpacing` finds a description with non-ASCII leading/trailing whitespace. ([@bcgraham])

## 2.23.2 (2023-08-09)

- Fix an incorrect autocorrect for `RSpec/ReceiveMessages` when method is only non-word character. ([@marocchino])
Expand Down Expand Up @@ -797,6 +799,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@aried3r]: https://github.com/aried3r
[@baberthal]: https://github.com/baberthal
[@backus]: https://github.com/backus
[@bcgraham]: https://github.com/bcgraham
[@biinari]: https://github.com/biinari
[@bmorrall]: https://github.com/bmorrall
[@bquorning]: https://github.com/bquorning
Expand Down
4 changes: 3 additions & 1 deletion lib/rubocop/cop/rspec/excessive_docstring_spacing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def excessive_whitespace?(text)

# @param text [String]
def strip_excessive_whitespace(text)
text.strip.gsub(/[[:blank:]]{2,}/, ' ')
text
.gsub(/[[:blank:]]{2,}/, ' ')
.gsub(/\A[[:blank:]]|[[:blank:]]\z/, '')
end

# @param node [RuboCop::AST::Node]
Expand Down
121 changes: 119 additions & 2 deletions spec/rubocop/cop/rspec/excessive_docstring_spacing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

it 'finds description with leading em space' do
expect_offense(<<-RUBY)
describe '  #mymethod' do
describe '\u3000\u3000#mymethod' do
^^^^^^^^^^^ Excessive whitespace.
end
RUBY
Expand All @@ -39,6 +39,19 @@
RUBY
end

it 'finds description with leading non-breaking space' do
expect_offense(<<-RUBY)
describe '\u00a0#mymethod' do
^^^^^^^^^^ Excessive whitespace.
end
RUBY

expect_correction(<<-RUBY)
describe '#mymethod' do
end
RUBY
end

it 'finds interpolated description with leading whitespace' do
expect_offense(<<-'RUBY')
describe " ##{:stuff}" do
Expand Down Expand Up @@ -67,7 +80,33 @@

it 'finds description with trailing em space' do
expect_offense(<<-RUBY)
describe '#mymethod  ' do
describe '#mymethod\u3000\u3000' do
^^^^^^^^^^^ Excessive whitespace.
end
RUBY

expect_correction(<<-RUBY)
describe '#mymethod' do
end
RUBY
end

it 'finds description with trailing non-breaking space' do
expect_offense(<<-RUBY)
describe '#mymethod\u00a0' do
^^^^^^^^^^ Excessive whitespace.
end
RUBY

expect_correction(<<-RUBY)
describe '#mymethod' do
end
RUBY
end

it 'finds description with leading and trailing non-breaking space' do
expect_offense(<<-RUBY)
describe '\u00a0#mymethod\u00a0' do
^^^^^^^^^^^ Excessive whitespace.
end
RUBY
Expand Down Expand Up @@ -205,6 +244,19 @@
RUBY
end

it 'finds description with leading non-breaking space' do
expect_offense(<<-RUBY)
context '\u00a0#mymethod' do
^^^^^^^^^^ Excessive whitespace.
end
RUBY

expect_correction(<<-RUBY)
context '#mymethod' do
end
RUBY
end

it 'finds interpolated description with leading whitespace' do
expect_offense(<<-'RUBY')
context " when doing something #{:stuff}" do
Expand All @@ -231,6 +283,32 @@
RUBY
end

it 'finds description with trailing non-breaking space' do
expect_offense(<<-RUBY)
context '#mymethod\u00a0' do
^^^^^^^^^^ Excessive whitespace.
end
RUBY

expect_correction(<<-RUBY)
context '#mymethod' do
end
RUBY
end

it 'finds description with leading and trailing non-breaking space' do
expect_offense(<<-RUBY)
context '\u00a0#mymethod\u00a0' do
^^^^^^^^^^^ Excessive whitespace.
end
RUBY

expect_correction(<<-RUBY)
context '#mymethod' do
end
RUBY
end

it 'finds interpolated description with trailing whitespace' do
expect_offense(<<-'RUBY')
context "when doing #{:stuff} " do
Expand Down Expand Up @@ -372,6 +450,19 @@
RUBY
end

it 'finds description with leading non-breaking space' do
expect_offense(<<-RUBY)
it '\u00a0does something' do
^^^^^^^^^^^^^^^ Excessive whitespace.
end
RUBY

expect_correction(<<-RUBY)
it 'does something' do
end
RUBY
end

it 'finds interpolated description with leading whitespace' do
expect_offense(<<-'RUBY')
it " does something #{:stuff}" do
Expand All @@ -398,6 +489,32 @@
RUBY
end

it 'finds description with trailing non-breaking space' do
expect_offense(<<-RUBY)
it 'does something\u00a0' do
^^^^^^^^^^^^^^^ Excessive whitespace.
end
RUBY

expect_correction(<<-RUBY)
it 'does something' do
end
RUBY
end

it 'finds description with leading and trailing non-breaking space' do
expect_offense(<<-RUBY)
it '\u00a0does something\u00a0' do
^^^^^^^^^^^^^^^^ Excessive whitespace.
end
RUBY

expect_correction(<<-RUBY)
it 'does something' do
end
RUBY
end

it 'finds interpolated description with trailing whitespace' do
expect_offense(<<-'RUBY')
it "does something #{:stuff} " do
Expand Down

0 comments on commit ff30ce1

Please sign in to comment.