Skip to content

Commit f502740

Browse files
authored
Merge pull request #596 from stanhu/sh-fix-uri-escaping
Generate URIs using Addressable
2 parents ddd57e7 + e92a669 commit f502740

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

fog-google.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Gem::Specification.new do |spec|
3434

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

37+
spec.add_dependency "addressable", ">= 2.7.0"
38+
3739
# Debugger
3840
# Locked because pry-byebug is broken with 13+
3941
# see: https://github.com/deivid-rodriguez/pry-byebug/issues/343

lib/fog/storage/google_json/utils.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'addressable'
2+
13
module Fog
24
module Storage
35
class GoogleJSON
@@ -19,10 +21,7 @@ def url(params, expires)
1921

2022
def host_path_query(params, expires)
2123
params[:headers]["Date"] = expires.to_i
22-
# implementation from CGI.escape, but without ' ' to '+' conversion
23-
params[:path] = params[:path].b.gsub(/([^a-zA-Z0-9_.\-~]+)/) { |m|
24-
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
25-
}.gsub("%2F", "/")
24+
params[:path] = ::Addressable::URI.encode_component(params[:path], ::Addressable::URI::CharacterClasses::PATH)
2625

2726
query = []
2827

test/unit/storage/test_json_requests.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,12 @@ def test_unescaped_slashes_in_url
4949
assert_match(/a\/b\/c/, url,
5050
"slashes should not be escaped with '%2F'")
5151
end
52+
53+
def test_unescaped_pluses_in_url
54+
url = @client.get_object_https_url("bucket",
55+
"a+c.ext",
56+
Time.now + 2 * 60)
57+
assert_match(/a\+c/, url,
58+
"pluses should not be escaped with '%2B'")
59+
end
5260
end

0 commit comments

Comments
 (0)