]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
Fix parsing iptables rules with hyphen in comments
authorArtur Molchanov <artur.molchanov@gmail.com>
Thu, 3 Oct 2019 21:09:13 +0000 (00:09 +0300)
committerArtur Molchanov <artur.molchanov@easybrain.com>
Thu, 3 Oct 2019 21:26:17 +0000 (00:26 +0300)
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
spec/fixtures/iptables/conversion_hash.rb

index 3bccc7198c15713abce0d20c8ce0ec21286be099..381906061dc66bb5a0ffc33fde50183c546a387f 100644 (file)
@@ -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(';')}\" ")
index 62d4db86b2e0f1402a09524722eecaf9b8ef0daf..b99db650b3e58ff05228019b2557617e9f19e9fe 100644 (file)
@@ -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',