Skip to content

Commit

Permalink
Fixed parsing of FFI's libffi ChangeLog
Browse files Browse the repository at this point in the history
Time.parse doesn't handle arbitrary input well.  This caused a bug when
it couldn't figure out the format of the time properly.  Now we fall
back to splitting on two spaces to find the time when Time raises a
NoMethodError.

Fixes #165
  • Loading branch information
drbrain committed Jan 4, 2013
1 parent bada629 commit 6dd8d41
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion History.rdoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
=== 4.0.0.preview3 / ??
=== 4.0.0.preview3.1 / ??

As a preview release, please file bugs for any problems you have with rdoc at
https://github.com/rdoc/rdoc/issues
Expand All @@ -25,6 +25,7 @@ to build HTML documentation when installing gems.)
by Marcus Stollsteimer
* RDoc now ignores methods defined on constants instead of creating a fake
module. Bug #163 by Zachary Scott.
* Fixed ChangeLog parsing for FFI gem. Bug #165 by Zachary Scott.

=== 4.0.0.preview2.1 / 2012-12-14

Expand Down
10 changes: 9 additions & 1 deletion lib/rdoc/parser/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ def create_items items

def group_entries entries
entries.group_by do |title, _|
Time.parse(title).strftime "%Y-%m-%d"
begin
Time.parse(title).strftime '%Y-%m-%d'
rescue NoMethodError, ArgumentError
time, = title.split ' ', 2
Time.parse(time).strftime '%Y-%m-%d'
end
end
end

Expand Down Expand Up @@ -139,6 +144,9 @@ def parse_entries
time = Time.parse entry_name
# HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other"
entry_name = nil unless entry_name =~ /#{time.year}/
rescue NoMethodError
time, = entry_name.split ' ', 2
time = Time.parse time
rescue ArgumentError
entry_name = nil
end
Expand Down
26 changes: 25 additions & 1 deletion test/test_rdoc_parser_changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ def test_group_entries
[ 'Tue Dec 4 08:32:10 2012 Eric Hodel <[email protected]>',
%w[three four]],
[ 'Mon Dec 3 20:28:02 2012 Koichi Sasada <[email protected]>',
%w[five six]]]
%w[five six]],
[ '2008-01-30 H.J. Lu <[email protected]>',
%w[seven eight]]]

expected = {
'2012-12-04' => [
Expand All @@ -193,6 +195,9 @@ def test_group_entries
'2012-12-03' => [
['Mon Dec 3 20:28:02 2012 Koichi Sasada <[email protected]>',
%w[five six]]],
'2008-01-30' => [
['2008-01-30 H.J. Lu <[email protected]>',
%w[seven eight]]],
}

assert_equal expected, parser.group_entries(entries)
Expand Down Expand Up @@ -226,6 +231,25 @@ def test_parse_entries
assert_equal expected, parser.parse_entries
end

def test_parse_entries_bad_time
parser = util_parser <<-ChangeLog
2008-01-30 H.J. Lu <[email protected]>
PR libffi/34612
* src/x86/sysv.S (ffi_closure_SYSV): Pop 4 byte from stack when
returning struct.
ChangeLog

expected = [
[ '2008-01-30 H.J. Lu <[email protected]>',
[ 'src/x86/sysv.S (ffi_closure_SYSV): Pop 4 byte from stack when ' +
'returning struct.']]
]

assert_equal expected, parser.parse_entries
end

def test_parse_entries_gnu
parser = util_parser <<-ChangeLog
1998-08-17 Richard Stallman <[email protected]>
Expand Down

0 comments on commit 6dd8d41

Please sign in to comment.