summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Sørensen <johan@johansorensen.com>2009-03-09 09:33:28 +0100
committerJohan Sørensen <johan@johansorensen.com>2009-04-22 15:15:55 +0200
commit16e20569d12be07a5a22b3d51c606c078141194c (patch)
treefc30ad6dfcef08a4e7ba5ddab1c41c5ac6c5c53c
parentecf4e929b2ce0cb952c091437bd1923e06579844 (diff)
downloadgitorious-mainline-outdated-16e20569d12be07a5a22b3d51c606c078141194c.zip
gitorious-mainline-outdated-16e20569d12be07a5a22b3d51c606c078141194c.tar.gz
gitorious-mainline-outdated-16e20569d12be07a5a22b3d51c606c078141194c.tar.bz2
Handle linking and showing branch names with a '#' character in them
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/controllers/commits_controller.rb3
-rw-r--r--test/functional/commits_controller_test.rb11
-rw-r--r--test/functional/trees_controller_test.rb19
4 files changed, 31 insertions, 4 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 2ebffc9..4bbd556 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -157,7 +157,7 @@ class ApplicationController < ActionController::Base
# turns ["foo", "bar"] route globbing parameters into "foo/bar"
def desplat_path(*paths)
- paths.join("/")
+ paths.flatten.compact.map{|p| CGI.unescape(p) }.join("/")
end
helper_method :desplat_path
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index 67c0b88..3197afe 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -24,8 +24,7 @@ class CommitsController < ApplicationController
def index
if params[:branch].blank?
redirect_to repo_owner_path(@repository, :project_repository_commits_in_ref_path, @project,
- @repository, @repository.head_candidate.name)
- return
+ @repository, @repository.head_candidate.name) and return
end
@git = @repository.git
@ref, _ = branch_and_path(params[:branch], @git)
diff --git a/test/functional/commits_controller_test.rb b/test/functional/commits_controller_test.rb
index 5f7c21f..d0613d8 100644
--- a/test/functional/commits_controller_test.rb
+++ b/test/functional/commits_controller_test.rb
@@ -149,7 +149,6 @@ class CommitsControllerTest < ActionController::TestCase
context "listing commits" do
-
setup do
@project = projects(:johans)
@repository = @project.repositories.first
@@ -210,6 +209,16 @@ class CommitsControllerTest < ActionController::TestCase
:repository_id => @repository.name, :id => "master", :format => "atom"}
assert @response.body.include?(%Q{<id>tag:test.host,2005:Grit::Commit/mycommitid</id>})
end
+
+ should "show branches with a # in them with great success" do
+ git_repo = Grit::Repo.new(grit_test_repo("dot_git"), :is_bare => true)
+ @repository.git.expects(:commit).with("ticket-#42") \
+ .returns(git_repo.commit("master"))
+ get :index, :project_id => @project.to_param, :repository_id => @repository.to_param,
+ :branch => ["ticket-%2342"]
+ assert_response :success
+ assert_equal "ticket-#42", assigns(:ref)
+ end
end
end
end
diff --git a/test/functional/trees_controller_test.rb b/test/functional/trees_controller_test.rb
index 30463f6..a5cbe12 100644
--- a/test/functional/trees_controller_test.rb
+++ b/test/functional/trees_controller_test.rb
@@ -125,6 +125,25 @@ class TreesControllerTest < ActionController::TestCase
end
end
+ context "Branch names containing a # character" do
+ should "show branches with a # in them with great success" do
+ git_repo = Grit::Repo.new(grit_test_repo("dot_git"), :is_bare => true)
+ @repository.git.expects(:commit).with("ticket-#42") \
+ .returns(git_repo.commit("master"))
+ get :show, :project_id => @project.to_param, :repository_id => @repository.to_param,
+ :branch_and_path => ["ticket-%2342"]
+ assert_response :success
+ assert_equal "ticket-#42", assigns(:ref)
+ end
+
+ should "urlencode # in branch names" do
+ Repository.any_instance.expects(:head_candidate_name).returns("ticket-#42")
+ get :index, :project_id => @project.to_param, :repository_id => @repository.to_param
+ assert_response :redirect
+ assert_redirected_to project_repository_tree_path(@project, @repository, ["ticket-#42"])
+ end
+ end
+
context "Archive downloads" do
setup do
ActiveMessaging::Gateway.connection.clear_messages