From: Joe Julian <me@joejulian.name>
Date: Fri, 24 May 2013 23:38:04 +0000 (-0700)
Subject: (#20912) Split argments while maintaining quoted strings
X-Git-Tag: 0.3.1~6^2~2
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e5f9e5e6222f95db9dc054440d2f02e730e8ade1;p=puppet-modules%2Fpuppetlabs-firewall.git

(#20912) Split argments while maintaining quoted strings

Github Bug: 182
Signed-off-by: Joe Julian <me@joejulian.name> (signed CLA)
---

diff --git a/lib/puppet/provider/firewall/iptables.rb b/lib/puppet/provider/firewall/iptables.rb
index c8e9c94..2db7dcf 100644
--- a/lib/puppet/provider/firewall/iptables.rb
+++ b/lib/puppet/provider/firewall/iptables.rb
@@ -277,30 +277,9 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir
   end
 
   def delete_args
-    count = []
-    line = properties[:line].gsub(/\-A/, '-D').split
-
-    # Grab all comment indices
-    line.each do |v|
-      if v =~ /"/
-        count << line.index(v)
-      end
-    end
-
-    if ! count.empty?
-      # Remove quotes and set first comment index to full string
-      line[count.first] = line[count.first..count.last].join(' ').gsub(/"/, '')
-
-      # Make all remaining comment indices nil
-      ((count.first + 1)..count.last).each do |i|
-        line[i] = nil
-      end
-    end
-
+    # Split into arguments
+    line = properties[:line].split(/\s(?=(?:[^"]|"[^"]*")*$)/).map{|v| v.gsub(/"/, '')}
     line.unshift("-t", properties[:table])
-
-    # Return array without nils
-    line.compact
   end
 
   # This method takes the resource, and attempts to generate the command line