Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't escape safe characters in keys #25

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fog/local/models/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/local/models/file_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down