From 29fc292b18de447831e11cb5265495e0107f08e3 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 24 Nov 2012 12:27:00 +0000 Subject: [PATCH] Respond with 404 instead of 500 when requesting a wiki diff with invalid versions (#12434). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10877 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/wiki_page.rb | 3 ++- test/functional/wiki_controller_test.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index c275cd83e..115b23d6d 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -112,7 +112,8 @@ class WikiPage < ActiveRecord::Base def diff(version_to=nil, version_from=nil) version_to = version_to ? version_to.to_i : self.content.version content_to = content.versions.find_by_version(version_to) - content_from = version_from ? content.versions.find_by_version(version_from.to_i) : content_to.previous + content_from = version_from ? content.versions.find_by_version(version_from.to_i) : content_to.try(:previous) + return nil unless content_to && content_from if content_from.version > content_to.version content_to, content_from = content_from, content_to diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 98fc20038..3673c7622 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -552,6 +552,16 @@ class WikiControllerTest < ActionController::TestCase assert_select 'span.diff_in', :text => 'Line added' end + def test_diff_with_invalid_version_should_respond_with_404 + get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99' + assert_response 404 + end + + def test_diff_with_invalid_version_from_should_respond_with_404 + get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99', :version_from => '98' + assert_response 404 + end + def test_annotate get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 assert_response :success @@ -576,6 +586,11 @@ class WikiControllerTest < ActionController::TestCase } end + def test_annotate_with_invalid_version_should_respond_with_404 + get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => '99' + assert_response 404 + end + def test_get_rename @request.session[:user_id] = 2 get :rename, :project_id => 1, :id => 'Another_page' -- 2.39.5