]> source.dussan.org Git - redmine.git/commitdiff
scm: mercurial: fix error on revision page for empty revision (#7307).
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Thu, 13 Jan 2011 12:04:51 +0000 (12:04 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Thu, 13 Jan 2011 12:04:51 +0000 (12:04 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4704 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository/mercurial.rb
test/functional/repositories_mercurial_controller_test.rb
test/unit/repository_mercurial_test.rb

index c38236fc8ddb65af68fc9b9150731adffc6d7a18..102c6dda8fec0a0e19a7f42f97ff11febc8db26a 100644 (file)
@@ -71,6 +71,7 @@ class Repository::Mercurial < Repository
 
   # Finds and returns a revision with a number or the beginning of a hash
   def find_changeset_by_name(name)
+    return nil if name.nil? || name.empty?
     if /[^\d]/ =~ name or name.to_s.size > 8
       e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s])
     else
index 1afe42571b3fda5f3145993c507f13f56080fecb..b565863c30fa4bff1de9d30c865e79345f0c786a 100644 (file)
@@ -195,6 +195,16 @@ class RepositoriesMercurialControllerTest < ActionController::TestCase
                  :attributes => { :class => 'line-num' },
                  :sibling => { :tag => 'td', :content => /watcher =/ }
     end
+
+    def test_empty_revision
+      @repository.fetch_changesets
+      @repository.reload
+      ['', ' ', nil].each do |r|
+        get :revision, :id => 1, :rev => r
+        assert_response 500
+        assert_error_tag :content => /was not found/
+      end
+    end
   else
     puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
     def test_fake; assert true end
index 8921acb765846641128687dfc47774075714a701..7523cfe9d5327efac7f17fe513270f3145cd439c 100644 (file)
@@ -154,6 +154,14 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
       assert_equal '2:400bb8672109', c.format_identifier
     end
 
+    def test_find_changeset_by_empty_name
+      @repository.fetch_changesets
+      @repository.reload
+      ['', ' ', nil].each do |r|
+        assert_nil @repository.find_changeset_by_name(r)
+      end
+    end
+
     def test_activities
       c = Changeset.new(:repository   => @repository,
                         :committed_on => Time.now,