Skip to content

Commit 899afc1

Browse files
Merge pull request #861 from Hexta/fix-rules-with-hyphen-wo-quotes
Fix parsing iptables rules with hyphen in comments
2 parents c5f2f22 + 2cee73f commit 899afc1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/puppet/provider/firewall/iptables.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def self.rule_to_hash(line, table, counter)
419419
if values =~ %r{-m comment --comment}
420420
ind = values.index('-m comment --comment')
421421
comments = values.scan(%r{-m comment --comment "((?:\\"|[^"])*)"})
422-
comments += values.scan(%r{-m comment --comment ([^"]+?)\b})
422+
comments += values.scan(%r{-m comment --comment ([^"\s]+)\b})
423423
values = values.gsub(%r{-m comment --comment (".*?[^\\"]"|[^ ].*)( |$)}, '')
424424
values = values.gsub(%r{-m comment --comment ([^"].*?)[ $]}, '')
425425
values.insert(ind, "-m comment --comment \"#{comments.join(';')}\" ")

spec/fixtures/iptables/conversion_hash.rb

+7
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@
254254
name: '9000 comment_without_quotes',
255255
},
256256
},
257+
'comments_without_quotes' => {
258+
line: '-A INPUT -s 192.168.0.1/32 -m comment --comment 100-comment_without-quotes',
259+
table: 'filter',
260+
params: {
261+
name: '100-comment_without-quotes',
262+
},
263+
},
257264
'string_escape_sequences' => {
258265
line: '-A INPUT -m comment --comment "000 parse escaped \\"s, \\"s, \\\'s, \\\'s, \\\\s and \\\\s"',
259266
table: 'filter',

0 commit comments

Comments
 (0)