Skip to content

Commit 9711e6f

Browse files
committed
Skip non-date logs by git-log
`RDoc::Parser::ChangeLog` mis-parses ChangeLog generated by git-log, because of too heuristic `Time.parse`. For instance, "commit 8187228de0142d3ac7950b7d977c2849e934c637" results in "8187-08-16", that is, day 228 in the year 8187.
1 parent 9d04064 commit 9711e6f

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

lib/rdoc/parser/changelog.rb

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# frozen_string_literal: true
2-
require 'time'
32

43
##
54
# A ChangeLog file parser.
@@ -106,14 +105,32 @@ def group_entries entries
106105
entries.group_by do |title, _|
107106
begin
108107
time = @time_cache[title]
109-
(time || Time.parse(title)).strftime '%Y-%m-%d'
108+
(time || parse_date(title)).strftime '%Y-%m-%d'
110109
rescue NoMethodError, ArgumentError
111110
time, = title.split ' ', 2
112-
Time.parse(time).strftime '%Y-%m-%d'
111+
parse_date(time).strftime '%Y-%m-%d'
113112
end
114113
end
115114
end
116115

116+
##
117+
# Parse date in ISO-8601, RFC-2822, or default of Git
118+
119+
def parse_date(date)
120+
case date
121+
when /\A\s*(\d+)-(\d+)-(\d+)(?: (\d+):(\d+):(\d+) *([-+]\d\d)(\d\d))?\b/
122+
Time.new($1, $2, $3, $4, $5, $6, ("#{$7}:#{$8}" if $7))
123+
when /\A\s*\w{3}, +(\d+) (\w{3}) (\d+) (\d+):(\d+):(\d+) *(?:([-+]\d\d)(\d\d))\b/
124+
Time.new($3, $2, $1, $4, $5, $6, ("#{$7}:#{$8}" if $7))
125+
when /\A\s*\w{3} (\w{3}) +(\d+) (\d+) (\d+):(\d+):(\d+) *(?:([-+]\d\d)(\d\d))\b/
126+
Time.new($3, $1, $2, $4, $5, $6, ("#{$7}:#{$8}" if $7))
127+
when /\A\s*\w{3} (\w{3}) +(\d+) (\d+):(\d+):(\d+) (\d+)\b/
128+
Time.new($6, $1, $2, $3, $4, $5)
129+
else
130+
raise ArgumentError, "bad date: #{date}"
131+
end
132+
end
133+
117134
##
118135
# Parses the entries in the ChangeLog.
119136
#
@@ -145,19 +162,10 @@ def parse_entries
145162
entry_name = $&
146163

147164
begin
148-
time = Time.parse entry_name
165+
time = parse_date entry_name
149166
@time_cache[entry_name] = time
150-
# HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other"
151-
entry_name = nil unless entry_name =~ /#{time.year}/
152-
rescue NoMethodError
153-
# HACK Ruby 2.1.2 and earlier raises NoMethodError if time part is absent
154-
entry_name.split ' ', 2
155167
rescue ArgumentError
156-
if /out of range/ =~ $!.message
157-
Time.parse(entry_name.split(' ', 2)[0]) rescue entry_name = nil
158-
else
159-
entry_name = nil
160-
end
168+
entry_name = nil
161169
end
162170

163171
entry_body = []

test/rdoc/test_rdoc_parser_changelog.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ def test_parse_entries
212212
change condition of using `opt_send_simple'.
213213
More method invocations can be simple.
214214
215+
commit\ 8187228de0142d3ac7950b7d977c2849e934c637
216+
215217
Other note that will be ignored
216218
217219
ChangeLog

0 commit comments

Comments
 (0)