提交 cce67b40 编写于 作者: M Mislav Marohnić

Merge pull request #741 from github/funky-branch-compare

Encode special characters in branch names for `compare` command
...@@ -13,6 +13,11 @@ Feature: hub compare ...@@ -13,6 +13,11 @@ Feature: hub compare
Then there should be no output Then there should be no output
And "open https://github.com/mislav/dotfiles/compare/feature/foo" should be run And "open https://github.com/mislav/dotfiles/compare/feature/foo" should be run
Scenario: Compare branch with funky characters
When I successfully run `hub compare 'my#branch!with.special+chars'`
Then there should be no output
And "open https://github.com/mislav/dotfiles/compare/my%23branch!with.special%2Bchars" should be run
Scenario: No args, no upstream Scenario: No args, no upstream
When I run `hub compare` When I run `hub compare`
Then the exit status should be 1 Then the exit status should be 1
...@@ -38,6 +43,13 @@ Feature: hub compare ...@@ -38,6 +43,13 @@ Feature: hub compare
Then there should be no output Then there should be no output
And "open https://github.com/mislav/dotfiles/compare/experimental" should be run And "open https://github.com/mislav/dotfiles/compare/experimental" should be run
Scenario: Current branch has funky characters
Given I am on the "feature" branch with upstream "origin/my#branch!with.special+chars"
And git "push.default" is set to "upstream"
When I successfully run `hub compare`
Then there should be no output
And "open https://github.com/mislav/dotfiles/compare/my%23branch!with.special%2Bchars" should be run
Scenario: Compare range Scenario: Compare range
When I successfully run `hub compare 1.0...fix` When I successfully run `hub compare 1.0...fix`
Then there should be no output Then there should be no output
......
...@@ -704,9 +704,9 @@ module Hub ...@@ -704,9 +704,9 @@ module Hub
path = case subpage path = case subpage
when 'commits' when 'commits'
"/commits/#{branch_in_url(branch)}" "/commits/#{branch_in_url(branch.short_name)}"
when 'tree', NilClass when 'tree', NilClass
"/tree/#{branch_in_url(branch)}" if branch and !branch.master? "/tree/#{branch_in_url(branch.short_name)}" if branch and !branch.master?
else else
"/#{subpage}" "/#{subpage}"
end end
...@@ -742,7 +742,8 @@ module Hub ...@@ -742,7 +742,8 @@ module Hub
end end
end end
path = '/compare/%s' % range escaped_range = range.include?('..') ? range : branch_in_url(range)
path = '/compare/%s' % escaped_range
project.web_url(path, api_client.config.method(:protocol)) project.web_url(path, api_client.config.method(:protocol))
end end
end end
...@@ -842,8 +843,10 @@ module Hub ...@@ -842,8 +843,10 @@ module Hub
# from the command line. # from the command line.
# #
def branch_in_url(branch) def branch_in_url(branch_name)
CGI.escape(branch.short_name).gsub("%2F", "/") branch_name.to_str.gsub(/[^\w!.*'():^~\/-]/) do |char|
'%' + char.unpack('H2' * char.bytesize).join('%').upcase
end
end end
def api_client def api_client
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册