-
-
Notifications
You must be signed in to change notification settings - Fork 136
Replace URI.encode, removed in Ruby 3.0, with Fog::OpenStack.escape #554
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
Open
tas50
wants to merge
1
commit into
fog:master
Choose a base branch
from
tas50:ruby3-fix-uri-encode
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| require 'spec_helper' | ||
|
|
||
| require 'fog/openstack/compute/requests/enable_service' | ||
| require 'fog/openstack/storage/requests/delete_multiple_objects' | ||
| require 'fog/openstack/workflow/v2/requests/get_action' | ||
|
|
||
| # Builds a Real instance without running its initializer (which would need | ||
| # credentials and a live endpoint) and captures what it hands to #request. | ||
| def capture_request(klass, response_body = '{}') | ||
| instance = klass.allocate | ||
| captured = nil | ||
| instance.define_singleton_method(:request) do |params, *_args| | ||
| captured = params | ||
| Excon::Response.new(:body => response_body) | ||
| end | ||
| yield instance | ||
| captured | ||
| end | ||
|
|
||
| describe 'URL escaping' do | ||
| describe 'Fog::OpenStack.escape' do | ||
| # This is why these call sites cannot use CGI.escape: in a URL *path* a | ||
| # '+' is a literal plus, not a space, so CGI.escape corrupts any name | ||
| # containing a space. | ||
| it 'encodes a space as %20 rather than +' do | ||
| assert_equal 'sp%20ace', Fog::OpenStack.escape('sp ace') | ||
| assert_equal 'sp+ace', CGI.escape('sp ace') | ||
| end | ||
|
|
||
| it 'leaves unreserved characters alone' do | ||
| assert_equal 'name-with.dots_and-dashes', Fog::OpenStack.escape('name-with.dots_and-dashes') | ||
| end | ||
|
|
||
| it 'escapes a slash by default but can be told to keep it' do | ||
| assert_equal 'a%2Fb', Fog::OpenStack.escape('a/b') | ||
| assert_equal 'a/b', Fog::OpenStack.escape('a/b', '/') | ||
| end | ||
| end | ||
|
|
||
| describe 'Workflow::V2 resource names in the path' do | ||
| it 'escapes the name into a single path segment' do | ||
| captured = capture_request(Fog::OpenStack::Workflow::V2::Real) do |real| | ||
| real.get_action('my action') | ||
| end | ||
| assert_equal 'actions/my%20action', captured[:path] | ||
| end | ||
|
|
||
| it 'escapes a slash inside the name so it cannot forge a path segment' do | ||
| captured = capture_request(Fog::OpenStack::Workflow::V2::Real) do |real| | ||
| real.get_action('a/b') | ||
| end | ||
| assert_equal 'actions/a%2Fb', captured[:path] | ||
| end | ||
| end | ||
|
|
||
| describe 'Storage#delete_multiple_objects' do | ||
| it 'escapes each name but keeps the container/object separator intact' do | ||
| captured = capture_request(Fog::OpenStack::Storage::Real) do |real| | ||
| real.delete_multiple_objects('my container', ['some object', 'plain']) | ||
| end | ||
| assert_equal "my%20container/some%20object\nmy%20container/plain", captured[:body] | ||
| end | ||
|
|
||
| it 'escapes bare names when no container is given' do | ||
| captured = capture_request(Fog::OpenStack::Storage::Real) do |real| | ||
| real.delete_multiple_objects(nil, ['some object']) | ||
| end | ||
| assert_equal 'some%20object', captured[:body] | ||
| end | ||
| end | ||
|
|
||
| describe 'Compute service optional params' do | ||
| it 'escapes the values' do | ||
| captured = capture_request(Fog::OpenStack::Compute::Real) do |real| | ||
| real.enable_service('host1', 'nova-compute', 'reason' => 'out of service') | ||
| end | ||
| assert_equal({'reason' => 'out%20of%20service'}, captured[:query]) | ||
| end | ||
|
|
||
| it 'does not mutate the hash the caller passed in' do | ||
| params = {'reason' => 'out of service'} | ||
| capture_request(Fog::OpenStack::Compute::Real) do |real| | ||
| real.enable_service('host1', 'nova-compute', params) | ||
| end | ||
| assert_equal({'reason' => 'out of service'}, params) | ||
| end | ||
| end | ||
|
|
||
| describe 'the whole library' do | ||
| it 'no longer calls URI.encode or URI.escape, removed in Ruby 3.0' do | ||
| lib = File.expand_path('../lib', __dir__) | ||
| offenders = Dir.glob("#{lib}/**/*.rb").select do |file| | ||
| File.read(file).match?(/\bURI\.(encode|escape)\b/) | ||
| end | ||
| assert_empty(offenders.map { |f| f.sub("#{lib}/", '') }) | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/BlockLength: Block has too many lines. [65/25]