From dd5f71538575e9bc9d6eb5036b07845e19f0ece4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 25 May 2013 21:27:25 +0200 Subject: [PATCH] fix unescaping multiple slashes in branch name in URLs --- features/browse.feature | 4 ++-- lib/hub/commands.rb | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/features/browse.feature b/features/browse.feature index accfa387..f61159a6 100644 --- a/features/browse.feature +++ b/features/browse.feature @@ -73,9 +73,9 @@ Feature: hub browse Scenario: Complex branch Given I am in "git://github.com/mislav/dotfiles.git" git repo - And I am on the "foo/bar" branch with upstream "origin/baz/qux" + And I am on the "foo/bar" branch with upstream "origin/baz/qux/moo" When I successfully run `hub browse` - Then "open https://github.com/mislav/dotfiles/tree/baz/qux" should be run + Then "open https://github.com/mislav/dotfiles/tree/baz/qux/moo" should be run Scenario: Wiki repo Given I am in "git://github.com/defunkt/hub.wiki.git" git repo diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 5823025c..1652f7b4 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -649,9 +649,9 @@ module Hub # $ hub browse -- wiki path = case subpage = args.shift when 'commits' - "/commits/#{CGI.escape(branch.short_name).sub("%2F", "/")}" + "/commits/#{branch_in_url(branch)}" when 'tree', NilClass - "/tree/#{CGI.escape(branch.short_name).sub("%2F", "/")}" if branch and !branch.master? + "/tree/#{branch_in_url(branch)}" if branch and !branch.master? else "/#{subpage}" end @@ -660,6 +660,11 @@ module Hub end end + def branch_in_url(branch) + require 'CGI' + CGI.escape(branch.short_name).gsub("%2F", "/") + end + # $ hub compare 1.0..fix # > open https://github.com/CURRENT_REPO/compare/1.0...fix # $ hub compare refactor -- GitLab