From e5f9e5e6222f95db9dc054440d2f02e730e8ade1 Mon Sep 17 00:00:00 2001 From: Joe Julian Date: Fri, 24 May 2013 16:38:04 -0700 Subject: [PATCH] (#20912) Split argments while maintaining quoted strings Github Bug: 182 Signed-off-by: Joe Julian (signed CLA) --- lib/puppet/provider/firewall/iptables.rb | 25 ++---------------------- 1 file changed, 2 insertions(+), 23 deletions(-) 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 -- 2.45.2