Skip to content

Commit

Permalink
Merge pull request #513 from karmix/tickets/master/MODULES-1967_parse…
Browse files Browse the repository at this point in the history
…-escape-sequences-from-iptables

(MODULES-1967) Parse escape sequences from iptables
  • Loading branch information
jonnytdevops committed Jun 18, 2015
2 parents 047ff3a + 16cfbdc commit 1c85e10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/puppet/provider/firewall/iptables.rb
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/fixtures/iptables/conversion_hash.rb
Expand Up @@ -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',
Expand Down

0 comments on commit 1c85e10

Please sign in to comment.