Skip to content

Commit 4380c02

Browse files
authored
fix(storage): Fix encoding of space characters in file names in signed_url v4
closes: googleapis#7835 pr: googleapis#7860
1 parent a28225f commit 4380c02

4 files changed

Lines changed: 24 additions & 24 deletions

File tree

google-cloud-storage/acceptance/storage/bucket_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@
195195

196196
_(bucket.lifecycle.last.created_before).must_be_kind_of Date
197197
_(bucket.lifecycle.last.created_before).must_equal created_before_2
198-
_(bucket.lifecycle.last.custom_time_before).must_be_kind_of DateTime
198+
_(bucket.lifecycle.last.custom_time_before).must_be_kind_of Date
199199
_(bucket.lifecycle.last.custom_time_before).must_equal custom_time_before_2
200-
_(bucket.lifecycle.last.noncurrent_time_before).must_be_kind_of DateTime
200+
_(bucket.lifecycle.last.noncurrent_time_before).must_be_kind_of Date
201201
_(bucket.lifecycle.last.noncurrent_time_before).must_equal noncurrent_time_before_2
202202

203203

@@ -210,13 +210,13 @@
210210
_(bucket.lifecycle.last.age).must_equal 20
211211
_(bucket.lifecycle.last.created_before).must_be_kind_of Date
212212
_(bucket.lifecycle.last.created_before).must_equal created_before_2
213-
_(bucket.lifecycle.last.custom_time_before).must_be_kind_of DateTime
213+
_(bucket.lifecycle.last.custom_time_before).must_be_kind_of Date
214214
_(bucket.lifecycle.last.custom_time_before).must_equal custom_time_before_2
215215
_(bucket.lifecycle.last.days_since_custom_time).must_equal 6
216216
_(bucket.lifecycle.last.days_since_noncurrent_time).must_equal 15
217217
_(bucket.lifecycle.last.is_live).must_equal false
218218
_(bucket.lifecycle.last.matches_storage_class).must_equal ["NEARLINE"]
219-
_(bucket.lifecycle.last.noncurrent_time_before).must_be_kind_of DateTime
219+
_(bucket.lifecycle.last.noncurrent_time_before).must_be_kind_of Date
220220
_(bucket.lifecycle.last.noncurrent_time_before).must_equal noncurrent_time_before_2
221221
_(bucket.lifecycle.last.num_newer_versions).must_equal 4
222222

google-cloud-storage/acceptance/storage/signed_url_v2_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
end
4545

4646
describe Google::Cloud::Storage::Project, :signed_url do
47-
it "should create a signed read url" do
47+
it "should create a signed read url with space in file name" do
4848
local_file = File.new files[:logo][:path]
49-
file = bucket.create_file local_file, "CloudLogoSignedUrlGetBucket.png"
49+
file = bucket.create_file local_file, "CloudLogoSignedUrl GetBucket.png"
5050

5151
five_min_from_now = 5 * 60
5252
url = storage.signed_url bucket.name, file.name, method: "GET",
@@ -69,9 +69,9 @@
6969
end
7070
end
7171

72-
it "should create a signed POST url version v2" do
72+
it "should create a signed POST url version v2 with space in file name" do
7373
url = storage.signed_url bucket.name,
74-
"CloudLogoProjectSignedUrlPost.png",
74+
"CloudLogoProjectSignedUrl Post.png",
7575
method: "POST",
7676
content_type: "image/png", # Required for V2
7777
headers: { "x-goog-resumable" => "start" },
@@ -90,9 +90,9 @@
9090
end
9191

9292
describe Google::Cloud::Storage::Bucket, :signed_url do
93-
it "should create a signed read url" do
93+
it "should create a signed read url with space in file name" do
9494
local_file = File.new files[:logo][:path]
95-
file = bucket.create_file local_file, "CloudLogoSignedUrlGetBucket.png"
95+
file = bucket.create_file local_file, "CloudLogoSignedUrl GetBucket.png"
9696

9797
five_min_from_now = 5 * 60
9898
url = bucket.signed_url file.name, method: "GET",
@@ -197,9 +197,9 @@
197197
end
198198

199199
describe Google::Cloud::Storage::File, :signed_url do
200-
it "should create a signed read url" do
200+
it "should create a signed read url with space in file name" do
201201
local_file = File.new files[:logo][:path]
202-
file = bucket.create_file local_file, "CloudLogoSignedUrlGetFile.png"
202+
file = bucket.create_file local_file, "CloudLogoSignedUrl GetFile.png"
203203

204204
five_min_from_now = 5 * 60
205205
url = file.signed_url method: "GET",

google-cloud-storage/acceptance/storage/signed_url_v4_test.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
end
4545

4646
describe Google::Cloud::Storage::Project, :signed_url do
47-
it "should create a signed read url version v4" do
47+
it "should create a signed read url version v4 with space in file name" do
4848
local_file = File.new files[:logo][:path]
49-
file = bucket.create_file local_file, "CloudLogoSignedUrlGetBucket.png"
49+
file = bucket.create_file local_file, "CloudLogoSignedUrl GetBucket.png"
5050

5151
five_min_from_now = 5 * 60
5252
url = storage.signed_url bucket.name, file.name, method: "GET",
@@ -69,10 +69,10 @@
6969
end
7070
end
7171

72-
it "should create a signed POST url version v4" do
72+
it "should create a signed POST url version v4 with space in file name" do
7373
five_min_from_now = 60 * 60
7474
url = storage.signed_url bucket.name,
75-
"CloudLogoProjectSignedUrlPost.png",
75+
"CloudLogoProjectSignedUrl Post.png",
7676
method: "POST",
7777
expires: five_min_from_now,
7878
headers: { "x-goog-resumable" => "start" },
@@ -90,9 +90,9 @@
9090
end
9191

9292
describe Google::Cloud::Storage::Bucket, :signed_url do
93-
it "should create a signed read url version v4" do
93+
it "should create a signed read url version v4 with space in file name" do
9494
local_file = File.new files[:logo][:path]
95-
file = bucket.create_file local_file, "CloudLogoSignedUrlGetBucket.png"
95+
file = bucket.create_file local_file, "CloudLogoSignedUrl GetBucket.png"
9696

9797
five_min_from_now = 5 * 60
9898
url = bucket.signed_url file.name, method: "GET",
@@ -197,9 +197,9 @@
197197
end
198198

199199
describe Google::Cloud::Storage::File, :signed_url do
200-
it "should create a signed read url version v4" do
200+
it "should create a signed read url version v4 with space in file name" do
201201
local_file = File.new files[:logo][:path]
202-
file = bucket.create_file local_file, "CloudLogoSignedUrlGetFile.png"
202+
file = bucket.create_file local_file, "CloudLogoSignedUrl GetFile.png"
203203

204204
five_min_from_now = 5 * 60
205205
url = file.signed_url method: "GET",
@@ -222,9 +222,9 @@
222222
end
223223
end
224224

225-
it "should create a signed POST url version v4" do
225+
it "should create a signed POST url version v4 with space in file name" do
226226
five_min_from_now = 60 * 60
227-
file = bucket.file "CloudLogoFileSignedUrlPost.png", skip_lookup: true
227+
file = bucket.file "CloudLogoFileSignedUrl Post.png", skip_lookup: true
228228
url = file.signed_url method: "POST",
229229
expires: five_min_from_now,
230230
headers: { "x-goog-resumable" => "start"},

google-cloud-storage/lib/google/cloud/storage/file/signer_v4.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def canonical_query query, algorithm, credential, goog_date, expires, signed_hea
273273
# Only the characters in the regex set [A-Za-z0-9.~_-] must be left un-escaped; all others must be
274274
# percent-encoded using %XX UTF-8 style.
275275
def escape_query_param str
276-
CGI.escape(str.to_s).gsub("%7E", "~").gsub("+", "%20")
276+
CGI.escape(str.to_s).gsub("%7E", "~").gsub "+", "%20"
277277
end
278278

279279
def host_name virtual_hosted_style, bucket_bound_hostname
@@ -287,7 +287,7 @@ def file_path path_style
287287
path = []
288288
path << "/#{@bucket_name}" if path_style
289289
path << "/#{String(@file_name)}" if @file_name && !@file_name.empty?
290-
CGI.escape(path.join).gsub "%2F", "/"
290+
CGI.escape(path.join).gsub("%2F", "/").gsub "+", "%20"
291291
end
292292

293293
##

0 commit comments

Comments
 (0)