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

Encode object name with URI instead of CGI #3081

Closed

Conversation

prapicault
Copy link
Contributor

Hi, this is a fix for issue #3064.
I've updated the code and the tests, and I have also tested the change in my setup.
The only thing that I have not been able to test is whether the bucket name needs to be encoded using CGI or URI.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Mar 28, 2019
@quartzmo quartzmo added the api: storage Issues related to the Cloud Storage API. label Mar 28, 2019
@quartzmo quartzmo requested a review from frankyn March 28, 2019 15:31
@quartzmo
Copy link
Member

Hi @prapicault, thank you for this PR!

The only thing that I have not been able to test is whether the bucket name needs to be encoded using CGI or URI.

I do not believe the bucket name needs to be encoded with either, since it contains only lowercase letters, numbers, dashes (-), underscores (_), and dots (.). (See also Encoding URI path parts.)

@frankyn Does this sound correct to you? Also, will this PR introduce a breaking change for users?

@@ -43,9 +43,9 @@ def self.from_bucket bucket, path
# The external path to the file.
def ext_path
escaped_path = String(@path).split("/").map do |node|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole method can be replaced with:

Addressable::URI.escape "/#{@bucket}/#{@path}"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@blowmage
Copy link
Contributor

Can you also add a direct dependency for the addressable gem to the google-cloud-storage.gemspec file?

@prapicault
Copy link
Contributor Author

prapicault commented Mar 28, 2019

Can you also add a direct dependency for the addressable gem to the google-cloud-storage.gemspec file?

Done

@prapicault
Copy link
Contributor Author

Still on working in the CLA :(

@frankyn
Copy link
Member

frankyn commented Mar 28, 2019

LGTM, found a related issue in the google-cloud-python lib: googleapis/google-cloud-python#3809

Percent encode the object name -- except '/' which is done by the split. Please don't remove that.

CGI.escape node
end.join("/")
"/#{CGI.escape @bucket}/#{escaped_path}"
Addressable::URI.escape "/#{@bucket}/#{@path}"
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankyn I think we are relying here on the behavior (seen in the unit tests below) of Addressable::URI.encode to not encode forward slashes at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, okay, I take back my last comment about not removing the split. Thanks for clarifying @quartzmo.

@quartzmo
Copy link
Member

Can you please replace require "cgi" with require "addressable/uri" in signer.rb? Thank you!

@blowmage
Copy link
Contributor

I believe CGI.encode is still being used in this file, so I would not remove that require.

@quartzmo
Copy link
Member

True, in url_escape. Should it be?

@blowmage
Copy link
Contributor

url_escape should probably be renamed param_escape, and it needs to use CGI. Its different because query strings values are escaped slightly different than paths.

quartzmo added a commit to quartzmo/google-cloud-ruby that referenced this pull request Apr 2, 2019
Remove trailing slash from path if no file.
Update CGI.escape to Addressable::URI.escape.

[refs googleapis#3081]
@quartzmo
Copy link
Member

quartzmo commented Apr 2, 2019

@prapicault How is it going? Are you blocked by the CLA? Or anything else?

@quartzmo
Copy link
Member

quartzmo commented Apr 3, 2019

@prapicault We are planning a release of google-cloud-storage, it would be great to include this change. Is there anything I can do to help?

@quartzmo
Copy link
Member

quartzmo commented Apr 4, 2019

@prapicault We would like to release this fix in the next few working days, are you making any progress with the CLA?

@quartzmo
Copy link
Member

quartzmo commented Apr 9, 2019

@prapicault I'm going to re-do this fix today in my own PR, but I will credit you for the find and the idea. I hope this is acceptable. We need to release the fix. Thank you!

@blowmage
Copy link
Contributor

blowmage commented Apr 9, 2019

This has been superseded by #3109.

@blowmage blowmage closed this Apr 9, 2019
@prapicault
Copy link
Contributor Author

Sorry for not being able to follow up. I just got the go to sign the CLA.
@quartzmo Thanks for pushing this forward and for the mention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. cla: no This human has *not* signed the Contributor License Agreement. 🚨 This issue needs some love.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants