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

Escape label names with URL characters #1297

Merged
merged 3 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/octokit/client/labels.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'cgi'
require "erb"

module Octokit
class Client
Expand Down Expand Up @@ -28,7 +28,7 @@ def labels(repo, options = {})
# @example Get the "V3 Addition" label from octokit/octokit.rb
# Octokit.label("octokit/octokit.rb", "V3 Addition")
def label(repo, name, options = {})
get "#{Repository.path repo}/labels/#{name}", options
get "#{Repository.path repo}/labels/#{ERB::Util.url_encode(name)}", options
end

# Add a label to a repository
Expand Down Expand Up @@ -56,7 +56,7 @@ def add_label(repo, label, color="ffffff", options = {})
# @example Update the label "Version 1.0" with new color "#cceeaa"
# Octokit.update_label("octokit/octokit.rb", "Version 1.0", {:color => "cceeaa"})
def update_label(repo, label, options = {})
patch "#{Repository.path repo}/labels/#{label}", options
patch "#{Repository.path repo}/labels/#{ERB::Util.url_encode(label)}", options
end

# Delete a label from a repository.
Expand All @@ -70,7 +70,7 @@ def update_label(repo, label, options = {})
# @example Delete the label "Version 1.0" from the repository.
# Octokit.delete_label!("octokit/octokit.rb", "Version 1.0")
def delete_label!(repo, label, options = {})
boolean_from_response :delete, "#{Repository.path repo}/labels/#{label}", options
boolean_from_response :delete, "#{Repository.path repo}/labels/#{ERB::Util.url_encode(label)}", options
end

# Remove a label from an Issue
Expand All @@ -85,7 +85,7 @@ def delete_label!(repo, label, options = {})
# @example Remove the label "Version 1.0" from the repository.
# Octokit.remove_label("octokit/octokit.rb", 23, "Version 1.0")
def remove_label(repo, number, label, options = {})
delete "#{Repository.path repo}/issues/#{number}/labels/#{label}", options
delete "#{Repository.path repo}/issues/#{number}/labels/#{ERB::Util.url_encode(label)}", options
end

# Remove all label from an Issue
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"http_interactions":[{"request":{"method":"delete","uri":"https://api.github.com/repos/api-playground/<GITHUB_TEST_REPOSITORY>/labels/test-label","body":{"encoding":"UTF-8","base64_string":"eyJjb2xvciI6ImVkZWRlZCJ9\n"},"headers":{"Accept":["application/vnd.github.beta+json"],"User-Agent":["Octokit Ruby Gem 2.0.0.pre"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":204,"message":"No Content"},"headers":{"Server":["GitHub.com"],"Date":["Mon, 17 Jun 2013 18:49:41 GMT"],"Connection":["keep-alive"],"Status":["204 No Content"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4917"],"X-Oauth-Scopes":["repo, user, gist"],"X-Accepted-Oauth-Scopes":["repo, public_repo"],"X-Github-Media-Type":["github.beta; format=json"],"X-Content-Type-Options":["nosniff"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-OAuth-Scopes, X-Accepted-OAuth-Scopes"],"Access-Control-Allow-Origin":["*"],"Vary":["Accept-Encoding"]},"body":{"encoding":"UTF-8","base64_string":""},"http_version":null},"recorded_at":"Mon, 17 Jun 2013 18:49:41 GMT"},{"request":{"method":"post","uri":"https://api.github.com/repos/api-playground/<GITHUB_TEST_REPOSITORY>/labels","body":{"encoding":"UTF-8","base64_string":"eyJuYW1lIjoidGVzdC1sYWJlbCIsImNvbG9yIjoiZWRlZGVkIn0=\n"},"headers":{"Accept":["application/vnd.github.beta+json"],"User-Agent":["Octokit Ruby Gem 2.0.0.pre"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":201,"message":"Created"},"headers":{"Server":["GitHub.com"],"Date":["Mon, 17 Jun 2013 18:49:41 GMT"],"Content-Type":["application/json; charset=utf-8"],"Connection":["keep-alive"],"Status":["201 Created"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4916"],"X-Oauth-Scopes":["repo, user, gist"],"X-Accepted-Oauth-Scopes":["repo, public_repo"],"Location":["https://api.github.com/repos/api-playground/<GITHUB_TEST_REPOSITORY>/labels/test-label"],"X-Github-Media-Type":["github.beta; format=json"],"X-Content-Type-Options":["nosniff"],"Content-Length":["120"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-OAuth-Scopes, X-Accepted-OAuth-Scopes"],"Access-Control-Allow-Origin":["*"],"Etag":["\"25a24312ad8e98fadb2f84b82f8806cd\""],"Cache-Control":["max-age=0, private, must-revalidate"]},"body":{"encoding":"UTF-8","base64_string":"eyJ1cmwiOiJodHRwczovL2FwaS5naXRodWIuY29tL3JlcG9zL2FwaS1wbGF5\nZ3JvdW5kLzxHSVRIVUJfVEVTVF9SRVBPU0lUT1JZPi9sYWJlbHMvdGVzdC1s\nYWJlbCIsIm5hbWUiOiJ0ZXN0LWxhYmVsIiwiY29sb3IiOiJlZGVkZWQifQ==\n"},"http_version":null},"recorded_at":"Mon, 17 Jun 2013 18:49:42 GMT"},{"request":{"method":"delete","uri":"https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/labels/test-label","body":{"encoding":"UTF-8","base64_string":"eyJjb2xvciI6ImVkZWRlZCJ9\n"},"headers":{"Accept":["application/vnd.github.v3+json"],"User-Agent":["Octokit Ruby Gem 3.0.0.pre"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":404,"message":"Not Found"},"headers":{"Server":["GitHub.com"],"Date":["Fri, 07 Mar 2014 20:44:11 GMT"],"Content-Type":["application/json; charset=utf-8"],"Transfer-Encoding":["chunked"],"Status":["404 Not Found"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4999"],"X-Ratelimit-Reset":["1394228651"],"X-Oauth-Scopes":["gist, repo, user"],"X-Accepted-Oauth-Scopes":[""],"X-Github-Media-Type":["github.v3; format=json"],"X-Content-Type-Options":["nosniff"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"X-Github-Request-Id":["4B413AB6:1E8A:6A42FB7:531A2F9B"]},"body":{"encoding":"UTF-8","base64_string":"eyJtZXNzYWdlIjoiTm90IEZvdW5kIiwiZG9jdW1lbnRhdGlvbl91cmwiOiJo\ndHRwOi8vZGV2ZWxvcGVyLmdpdGh1Yi5jb20vdjMifQ==\n"},"http_version":null},"recorded_at":"Fri, 07 Mar 2014 20:44:08 GMT"},{"request":{"method":"post","uri":"https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/labels","body":{"encoding":"UTF-8","base64_string":"eyJuYW1lIjoidGVzdC1sYWJlbCIsImNvbG9yIjoiZWRlZGVkIn0=\n"},"headers":{"Accept":["application/vnd.github.v3+json"],"User-Agent":["Octokit Ruby Gem 3.0.0.pre"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":201,"message":"Created"},"headers":{"Server":["GitHub.com"],"Date":["Fri, 07 Mar 2014 20:44:11 GMT"],"Content-Type":["application/json; charset=utf-8"],"Status":["201 Created"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4998"],"X-Ratelimit-Reset":["1394228651"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Etag":["\"04e28858f734991013307bf94ad23672\""],"X-Oauth-Scopes":["gist, repo, user"],"X-Accepted-Oauth-Scopes":[""],"Location":["https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/labels/test-label"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP"],"X-Github-Media-Type":["github.v3; format=json"],"X-Content-Type-Options":["nosniff"],"Content-Length":["116"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"X-Github-Request-Id":["4B413AB6:1E89:5627013:531A2F9B"]},"body":{"encoding":"UTF-8","base64_string":"eyJ1cmwiOiJodHRwczovL2FwaS5naXRodWIuY29tL3JlcG9zLzxHSVRIVUJf\nTE9HSU4+LzxHSVRIVUJfVEVTVF9SRVBPU0lUT1JZPi9sYWJlbHMvdGVzdC1s\nYWJlbCIsIm5hbWUiOiJ0ZXN0LWxhYmVsIiwiY29sb3IiOiJlZGVkZWQifQ==\n"},"http_version":null},"recorded_at":"Fri, 07 Mar 2014 20:44:09 GMT"}],"recorded_with":"VCR 2.8.0"}
{"http_interactions":[{"request":{"method":"delete","uri":"https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/labels/test-label","body":{"encoding":"UTF-8","base64_string":"e30=\n"},"headers":{"Accept":["application/vnd.github.v3+json"],"User-Agent":["Octokit Ruby Gem 4.19.0"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":204,"message":"No Content"},"headers":{"Server":["GitHub.com"],"Date":["Wed, 28 Oct 2020 20:03:43 GMT"],"Status":["204 No Content"],"X-Oauth-Scopes":["admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages"],"X-Accepted-Oauth-Scopes":[""],"X-Github-Media-Type":["github.v3; format=json"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4723"],"X-Ratelimit-Reset":["1603918394"],"X-Ratelimit-Used":["277"],"Access-Control-Expose-Headers":["ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset"],"Access-Control-Allow-Origin":["*"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Frame-Options":["deny"],"X-Content-Type-Options":["nosniff"],"X-Xss-Protection":["1; mode=block"],"Referrer-Policy":["origin-when-cross-origin, strict-origin-when-cross-origin"],"Content-Security-Policy":["default-src 'none'"],"Vary":["Accept-Encoding, Accept, X-Requested-With"],"X-Github-Request-Id":["CB62:01C8:EF81F1:17EBAAE:5F99CE9F"]},"body":{"encoding":"UTF-8","base64_string":""},"http_version":null},"recorded_at":"Wed, 28 Oct 2020 20:03:43 GMT"},{"request":{"method":"post","uri":"https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/labels","body":{"encoding":"UTF-8","base64_string":"eyJuYW1lIjoidGVzdC1sYWJlbCIsImNvbG9yIjoiZWRlZGVkIn0=\n"},"headers":{"Accept":["application/vnd.github.v3+json"],"User-Agent":["Octokit Ruby Gem 4.19.0"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":201,"message":"Created"},"headers":{"Server":["GitHub.com"],"Date":["Wed, 28 Oct 2020 20:03:44 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["200"],"Status":["201 Created"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding, Accept, X-Requested-With"],"Etag":["\"c73beb984ac16fb9d5db17a3b86f50e44b7928d8794a053177e62a95d92bfb4c\""],"X-Oauth-Scopes":["admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages"],"X-Accepted-Oauth-Scopes":[""],"Location":["https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/labels/test-label"],"X-Github-Media-Type":["github.v3; format=json"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4720"],"X-Ratelimit-Reset":["1603918394"],"X-Ratelimit-Used":["280"],"Access-Control-Expose-Headers":["ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset"],"Access-Control-Allow-Origin":["*"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Frame-Options":["deny"],"X-Content-Type-Options":["nosniff"],"X-Xss-Protection":["1; mode=block"],"Referrer-Policy":["origin-when-cross-origin, strict-origin-when-cross-origin"],"Content-Security-Policy":["default-src 'none'"],"X-Github-Request-Id":["CB65:526A:1B007A:4CC5BF:5F99CE9F"]},"body":{"encoding":"UTF-8","base64_string":"eyJpZCI6MjQ2Mjc1NjUxOCwibm9kZV9pZCI6Ik1EVTZUR0ZpWld3eU5EWXlO\nelUyTlRFNCIsInVybCI6Imh0dHBzOi8vYXBpLmdpdGh1Yi5jb20vcmVwb3Mv\nPEdJVEhVQl9MT0dJTj4vPEdJVEhVQl9URVNUX1JFUE9TSVRPUlk+L2xhYmVs\ncy90ZXN0LWxhYmVsIiwibmFtZSI6InRlc3QtbGFiZWwiLCJjb2xvciI6ImVk\nZWRlZCIsImRlZmF1bHQiOmZhbHNlLCJkZXNjcmlwdGlvbiI6bnVsbH0=\n"},"http_version":null},"recorded_at":"Wed, 28 Oct 2020 20:03:44 GMT"}],"recorded_with":"VCR 5.1.0"}
Loading