Skip to content

Commit

Permalink
(MODULES-1967) Parse escape sequences from iptables
Browse files Browse the repository at this point in the history
  • Loading branch information
karmix committed Jun 10, 2015
1 parent e7121fe commit 16cfbdc
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
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,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
Original file line number Diff line number Diff line change
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 16cfbdc

Please sign in to comment.