From d6b31257b04d858450429c667a08ca686eec6ff7 Mon Sep 17 00:00:00 2001 From: Seth Boyles Date: Wed, 19 Jan 2022 23:55:13 +0000 Subject: [PATCH] Don't escape safe characters in keys * #24 fixes regression introduced in 0.7 Authored-by: Seth Boyles --- lib/fog/local/models/file.rb | 2 +- tests/local/models/file_tests.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/fog/local/models/file.rb b/lib/fog/local/models/file.rb index c270568..f4b8470 100644 --- a/lib/fog/local/models/file.rb +++ b/lib/fog/local/models/file.rb @@ -107,7 +107,7 @@ def directory=(new_directory) end def uri_escape(string) - string.b.gsub(/([^a-zA-Z0-9_.\-~]+)/) do |m| + string.b.gsub(URI::DEFAULT_PARSER.regexp[:UNSAFE]) do |m| '%' + m.unpack('H2' * m.bytesize).join('%').upcase end end diff --git a/tests/local/models/file_tests.rb b/tests/local/models/file_tests.rb index 477e149..5ac037a 100644 --- a/tests/local/models/file_tests.rb +++ b/tests/local/models/file_tests.rb @@ -41,6 +41,17 @@ directory = connection.directories.new(:key => 'my directory') file = directory.files.new(:key => 'my file.txt') + file.public_url + end + + tests('when key has safe characters'). + returns('http://example.com/files/my/directory/my/file.txt') do + @options[:endpoint] = 'http://example.com/files' + + connection = Fog::Local::Storage.new(@options) + directory = connection.directories.new(:key => 'my/directory') + file = directory.files.new(:key => 'my/file.txt') + file.public_url end end