From 2cee73f190c27ff7d4c14cc7afbd02bbc73e8b5a Mon Sep 17 00:00:00 2001 From: Artur Molchanov Date: Fri, 4 Oct 2019 00:09:13 +0300 Subject: [PATCH] Fix parsing iptables rules with hyphen in comments Fix parsing rules which have comments including a hyphen mark and no space character. Example: 101-a-b-c. --- lib/puppet/provider/firewall/iptables.rb | 2 +- spec/fixtures/iptables/conversion_hash.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/firewall/iptables.rb b/lib/puppet/provider/firewall/iptables.rb index 3bccc71..3819060 100644 --- a/lib/puppet/provider/firewall/iptables.rb +++ b/lib/puppet/provider/firewall/iptables.rb @@ -419,7 +419,7 @@ Puppet::Type.type(:firewall).provide :iptables, parent: Puppet::Provider::Firewa if values =~ %r{-m comment --comment} ind = values.index('-m comment --comment') comments = values.scan(%r{-m comment --comment "((?:\\"|[^"])*)"}) - comments += values.scan(%r{-m comment --comment ([^"]+?)\b}) + comments += values.scan(%r{-m comment --comment ([^"\s]+)\b}) values = values.gsub(%r{-m comment --comment (".*?[^\\"]"|[^ ].*)( |$)}, '') values = values.gsub(%r{-m comment --comment ([^"].*?)[ $]}, '') values.insert(ind, "-m comment --comment \"#{comments.join(';')}\" ") diff --git a/spec/fixtures/iptables/conversion_hash.rb b/spec/fixtures/iptables/conversion_hash.rb index 62d4db8..b99db65 100644 --- a/spec/fixtures/iptables/conversion_hash.rb +++ b/spec/fixtures/iptables/conversion_hash.rb @@ -254,6 +254,13 @@ ARGS_TO_HASH = { name: '9000 comment_without_quotes', }, }, + 'comments_without_quotes' => { + line: '-A INPUT -s 192.168.0.1/32 -m comment --comment 100-comment_without-quotes', + table: 'filter', + params: { + name: '100-comment_without-quotes', + }, + }, 'string_escape_sequences' => { line: '-A INPUT -m comment --comment "000 parse escaped \\"s, \\"s, \\\'s, \\\'s, \\\\s and \\\\s"', table: 'filter', -- 2.45.2