Skip to content

Commit

Permalink
Merge pull request #530 from krokodaxl/unescape-path-slashes
Browse files Browse the repository at this point in the history
Unescape slashes in urls
  • Loading branch information
Temikus authored Jun 11, 2021
2 parents 32bd2e8 + 5494a75 commit 08b802f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/fog/storage/google_json/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ def url(params, expires)
def host_path_query(params, expires)
params[:headers]["Date"] = expires.to_i
# implementation from CGI.escape, but without ' ' to '+' conversion
params[:path] = params[:path].b.gsub(/([^a-zA-Z0-9_.\-~]+)/) do |m|
params[:path] = params[:path].b.gsub(/([^a-zA-Z0-9_.\-~]+)/) { |m|
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
end
}.gsub("%2F", "/")

query = []

if params[:query]
Expand Down
8 changes: 8 additions & 0 deletions test/unit/storage/test_json_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ def test_put_url_path_is_properly_escaped
assert_match(/just%20some%20file\.json/, url,
"space should be escaped with '%20'")
end

def test_unescaped_slashes_in_url
url = @client.get_object_https_url("bucket",
"a/b/c.ext",
Time.now + 2 * 60)
assert_match(/a\/b\/c/, url,
"slashes should not be escaped with '%2F'")
end
end

0 comments on commit 08b802f

Please sign in to comment.