Skip to content
Open
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/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def self.get_supported_microversion(supported_versions, uri, auth_token, connect

# CGI.escape, but without special treatment on spaces
def self.escape(str, extra_exclude_chars = '')
str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do
str.gsub(/([^a-zA-Z0-9_.#{extra_exclude_chars}-]+)/) do
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
end
end
Expand Down
27 changes: 27 additions & 0 deletions spec/openstack_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

describe Fog::OpenStack do
describe ".escape" do
describe "when string includes dash" do
it "does not escape dashes" do
str = "this-is-hypenated"
assert_equal str, Fog::OpenStack.escape(str)
end
end

describe "when string includes dash and extra characters" do
it "does not escape dashes" do
str = "this-is-hypenated/"
assert_equal str, Fog::OpenStack.escape(str, "/")
end
end

describe "when string includes dash without extra characters" do
it "does not escape dashes" do
str = "this-is-hypenated/"
expected = "this-is-hypenated%2F"
assert_equal expected, Fog::OpenStack.escape(str)
end
end
end
end