Commits

jplang  committed b390438

Respond with 404 instead of 500 when requesting a wiki diff with invalid versions (#12434).

  • Participants
  • Parent commits 6745a0d

Comments (0)

Files changed (2)

File app/models/wiki_page.rb

   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

File test/functional/wiki_controller_test.rb

     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
     }
   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'