diff --git a/lib/puppet/provider/firewall/iptables.rb b/lib/puppet/provider/firewall/iptables.rb index 59da729a8..8d5904630 100644 --- a/lib/puppet/provider/firewall/iptables.rb +++ b/lib/puppet/provider/firewall/iptables.rb @@ -392,8 +392,16 @@ def self.rule_to_hash(line, table, counter) values.slice!('-A') keys << :chain - # Here we generate the main hash - keys.zip(values.scan(/"[^"]*"|\S+/).reverse) { |f, v| hash[f] = v.gsub(/"/, '') } + # Here we generate the main hash by scanning arguments off the values + # string, handling any quoted characters present in the value, and then + # zipping the values with the array of keys. + keys.zip(values.scan(/("([^"\\]|\\.)*"|\S+)/).transpose[0].reverse) do |f, v| + if v =~ /^".*"$/ then + hash[f] = v.sub(/^"(.*)"$/, '\1').gsub(/\\(\\|'|")/, '\1') + else + hash[f] = v.dup + end + end ##################### # POST PARSE CLUDGING diff --git a/spec/fixtures/iptables/conversion_hash.rb b/spec/fixtures/iptables/conversion_hash.rb index ecd0887fc..7ec0e3d31 100644 --- a/spec/fixtures/iptables/conversion_hash.rb +++ b/spec/fixtures/iptables/conversion_hash.rb @@ -231,6 +231,13 @@ :source => '192.168.0.1/32', }, }, + 'string_escape_sequences' => { + :line => '-A INPUT -m comment --comment "000 parse escaped \\"s, \\\'s, and \\\\s"', + :table => 'filter', + :params => { + :name => '000 parse escaped "s, \'s, and \\s', + }, + }, 'log_level_debug' => { :line => '-A INPUT -m comment --comment "956 INPUT log-level" -m state --state NEW -j LOG --log-level 7', :table => 'filter',