]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
(#20912) Split argments while maintaining quoted strings
authorJoe Julian <me@joejulian.name>
Fri, 24 May 2013 23:38:04 +0000 (16:38 -0700)
committerJoe Julian <me@joejulian.name>
Fri, 24 May 2013 23:38:04 +0000 (16:38 -0700)
Github Bug: 182
Signed-off-by: Joe Julian <me@joejulian.name> (signed CLA)
lib/puppet/provider/firewall/iptables.rb

index c8e9c94789c9d326584fc2c99d65ca7e3c8e3c11..2db7dcfa2e73aa42de0d3d9975223c0718861cd2 100644 (file)
@@ -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