Skip to content

Commit

Permalink
check that a lastmod date was sent before trying to convert it to a date
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Apr 30, 2014
1 parent efb302f commit 2dc10f2
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/controllers/sitemaps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ def validate_resource
errors = ActiveModel::Errors.new url

if url.response.status == 200

last_modified_date = DateTime.parse(url.lastmod)

if url.lastmod.length <= 10
# yyyy-mm-dd granularity
last_modified_date += 1.day
end

if url.response_last_modified && url.lastmod && url.response_last_modified > last_modified_date
errors.add "last modified" "expected #{url.lastmod} to be later than #{url.response_last_modified}"

if url.response_last_modified && url.lastmod

last_modified_date = DateTime.parse(url.lastmod)

if url.lastmod.length <= 10
# yyyy-mm-dd granularity
last_modified_date += 1.day
end

if url.response_last_modified && url.lastmod && url.response_last_modified > last_modified_date
errors.add "last modified" "expected #{url.lastmod} to be later than #{url.response_last_modified}"
end
end

if url.md && url.md[:length] && url.response_length != url.md[:length]
Expand Down

0 comments on commit 2dc10f2

Please sign in to comment.