diff --git a/lib/fog/openstack.rb b/lib/fog/openstack.rb index b1d308dae..aea8cdc43 100644 --- a/lib/fog/openstack.rb +++ b/lib/fog/openstack.rb @@ -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 diff --git a/spec/openstack_spec.rb b/spec/openstack_spec.rb new file mode 100644 index 000000000..8f8b6ee6f --- /dev/null +++ b/spec/openstack_spec.rb @@ -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 \ No newline at end of file