Skip to content

Commit

Permalink
Merge pull request #596 from stanhu/sh-fix-uri-escaping
Browse files Browse the repository at this point in the history
Generate URIs using Addressable
  • Loading branch information
geemus authored Jun 15, 2023
2 parents ddd57e7 + e92a669 commit f502740
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions fog-google.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Gem::Specification.new do |spec|

spec.add_dependency "google-cloud-env", "~> 1.2"

spec.add_dependency "addressable", ">= 2.7.0"

# Debugger
# Locked because pry-byebug is broken with 13+
# see: https://github.com/deivid-rodriguez/pry-byebug/issues/343
Expand Down
7 changes: 3 additions & 4 deletions lib/fog/storage/google_json/utils.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'addressable'

module Fog
module Storage
class GoogleJSON
Expand All @@ -19,10 +21,7 @@ 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_.\-~]+)/) { |m|
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
}.gsub("%2F", "/")
params[:path] = ::Addressable::URI.encode_component(params[:path], ::Addressable::URI::CharacterClasses::PATH)

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 @@ -49,4 +49,12 @@ def test_unescaped_slashes_in_url
assert_match(/a\/b\/c/, url,
"slashes should not be escaped with '%2F'")
end

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

0 comments on commit f502740

Please sign in to comment.