Skip to content

Commit

Permalink
cmdparse.rb: fix a nil.sub bug (gettalong#3)
Browse files Browse the repository at this point in the history
When we have to format a word that is longer than the available space,
`paragraph.slice!(pattern)` will return nil. This case should be
detected by the `until` (and it is then correctly handed) but
unfortunately there is a `sub` call after the `slice!` which will error
out before. Fix this by only calling the `sub` if the result is not nil.
  • Loading branch information
DamienRobert authored and gettalong committed Oct 12, 2018
1 parent cd7007a commit a33c856
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cmdparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def format(content, width: command_parser.help_line_width,
content.split(/\n\n/).map do |paragraph|
lines = []
until paragraph.empty?
unless (str = paragraph.slice!(pattern).sub(/[ \n]\z/, ''))
unless (str = paragraph.slice!(pattern)) and (str = str.sub(/[ \n]\z/, ''))
str = paragraph.slice!(0, line_length)
end
lines << (lines.empty? && !indent_first_line ? '' : ' ' * indent) + str.tr("\n", ' ')
Expand Down

0 comments on commit a33c856

Please sign in to comment.