Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove_label fails with 404 when label name contains spaces #560

Closed
domcleal opened this issue Feb 13, 2015 · 2 comments · Fixed by #562
Closed

remove_label fails with 404 when label name contains spaces #560

domcleal opened this issue Feb 13, 2015 · 2 comments · Fixed by #562

Comments

@domcleal
Copy link

client.remove_label(repo, pr, 'help wanted') fails with a 404 response from the GitHub API even when the "help wanted" label exists, as the spaces in the label name aren't escaped correctly.

2.0.0-p353 :002 > c.remove_label('domcleal/test', 2, 'help wanted')                                                                     
Octokit::NotFound: DELETE https://api.github.com/repos/domcleal/test/issues/2/labels/help+wanted: 404 - Label does not exist // See: https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
        from /home/dcleal/code/git/octokit.rb/lib/octokit/response/raise_error.rb:16:in `on_complete'
        from /home/dcleal/.rvm/gems/ruby-2.0.0-p353@tmp/gems/faraday-0.9.1/lib/faraday/response.rb:9:in `block in call'
        from /home/dcleal/.rvm/gems/ruby-2.0.0-p353@tmp/gems/faraday-0.9.1/lib/faraday/response.rb:57:in `on_complete'
        from /home/dcleal/.rvm/gems/ruby-2.0.0-p353@tmp/gems/faraday-0.9.1/lib/faraday/response.rb:8:in `call'
        from /home/dcleal/.rvm/gems/ruby-2.0.0-p353@tmp/gems/faraday-0.9.1/lib/faraday/rack_builder.rb:139:in `build_response'
        from /home/dcleal/.rvm/gems/ruby-2.0.0-p353@tmp/gems/faraday-0.9.1/lib/faraday/connection.rb:377:in `run_request'
        from /home/dcleal/.rvm/gems/ruby-2.0.0-p353@tmp/gems/faraday-0.9.1/lib/faraday/connection.rb:140:in `delete'
        from /home/dcleal/.rvm/gems/ruby-2.0.0-p353@tmp/gems/sawyer-0.6.0/lib/sawyer/agent.rb:94:in `call'
        from /home/dcleal/code/git/octokit.rb/lib/octokit/client.rb:339:in `request'
        from /home/dcleal/code/git/octokit.rb/lib/octokit/client.rb:171:in `delete'
        from /home/dcleal/code/git/octokit.rb/lib/octokit/client/labels.rb:88:in `remove_label'
        from (irb):2

remove_label (and other methods in the same file) uses CGI.escape on the label name before making the request (https://github.com/octokit/octokit.rb/blob/568745f/lib/octokit/client/labels.rb#L88). CGI.escape is escaping the space as a + rather than %20, which the API doesn't appear to accept.

The request method escapes too (https://github.com/octokit/octokit.rb/blob/568745f/lib/octokit/client.rb#L339), but this isn't complete - it won't escape special URL characters such as "?" in label names, so removing CGI.escape would break those labels instead. Unfortunately changing CGI.escape to another method (ERB::Util.url_encode?) that escapes spaces as %20 will only cause the % to be escaped again in the request method.

domcleal pushed a commit to theforeman/prprocessor that referenced this issue Feb 13, 2015
pengwynn added a commit that referenced this issue Feb 13, 2015
Properly handle labels with spaces. Remove `CGI.escape`, let Addressable
handle it.

Fixes #560
Fixes #561
@kareem
Copy link

kareem commented May 29, 2017

@pengwynn I'm getting a 404 when deleting a label with a forward slash in it e.g. ("foo/bar"). Octokit 4.6.2. Should I open up a new issue or is this accepted behavior?

> d = client.delete_label!("org/repo", "foo/bar")
delete https://api.github.com/repos/org/repo/labels/foo/bar
[snip]
status: "404 Not Found"
=> false

@pengwynn
Copy link
Collaborator

@kareem we may have had a regression since bumping Addressable in the past two years. A new issue would be great. Bonus points for patch or at least a failing test. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants