Skip to content

Commit 16cfbdc

Browse files
committed
(MODULES-1967) Parse escape sequences from iptables
1 parent e7121fe commit 16cfbdc

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/puppet/provider/firewall/iptables.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,16 @@ def self.rule_to_hash(line, table, counter)
364364
values.slice!('-A')
365365
keys << :chain
366366

367-
# Here we generate the main hash
368-
keys.zip(values.scan(/"[^"]*"|\S+/).reverse) { |f, v| hash[f] = v.gsub(/"/, '') }
367+
# Here we generate the main hash by scanning arguments off the values
368+
# string, handling any quoted characters present in the value, and then
369+
# zipping the values with the array of keys.
370+
keys.zip(values.scan(/("([^"\\]|\\.)*"|\S+)/).transpose[0].reverse) do |f, v|
371+
if v =~ /^".*"$/ then
372+
hash[f] = v.sub(/^"(.*)"$/, '\1').gsub(/\\(\\|'|")/, '\1')
373+
else
374+
hash[f] = v.dup
375+
end
376+
end
369377

370378
#####################
371379
# POST PARSE CLUDGING

spec/fixtures/iptables/conversion_hash.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@
231231
:source => '192.168.0.1/32',
232232
},
233233
},
234+
'string_escape_sequences' => {
235+
:line => '-A INPUT -m comment --comment "000 parse escaped \\"s, \\\'s, and \\\\s"',
236+
:table => 'filter',
237+
:params => {
238+
:name => '000 parse escaped "s, \'s, and \\s',
239+
},
240+
},
234241
'log_level_debug' => {
235242
:line => '-A INPUT -m comment --comment "956 INPUT log-level" -m state --state NEW -j LOG --log-level 7',
236243
:table => 'filter',

0 commit comments

Comments
 (0)