Skip to content

Commit 63107de

Browse files
Remove trash from the middle of the main parse
The regular parse mechanisms can handle table, chain, and comment(s) on their own already, if a single space character is added to the head of the rule. :table was already in @resource_map, :chain is added to the parse output by the unnecessary special mechanism anyway, and :name already grabs ALL comments successfully since the escaping fixes. 'line' is used instead of 'line.dup' because string addition returns a new string, so String#dup would be redundant.
1 parent 5af68c3 commit 63107de

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

lib/puppet/provider/firewall/ip6tables.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def self.iptables_save(*args)
9393

9494
@resource_map = {
9595
burst: '--limit-burst',
96+
chain: '-A',
9697
checksum_fill: '--checksum-fill',
9798
clamp_mss_to_pmtu: '--clamp-mss-to-pmtu',
9899
condition: '--condition',

lib/puppet/provider/firewall/iptables.rb

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585

8686
@resource_map = {
8787
burst: '--limit-burst',
88+
chain: '-A',
8889
checksum_fill: '--checksum-fill',
8990
clamp_mss_to_pmtu: '--clamp-mss-to-pmtu',
9091
condition: '--condition',
@@ -512,7 +513,7 @@ def self.instances
512513
def self.rule_to_hash(line, table, counter)
513514
hash = {}
514515
keys = []
515-
values = line.dup
516+
values = ' ' + line
516517

517518
####################
518519
# PRE-PARSE CLUDGING
@@ -656,23 +657,6 @@ def self.rule_to_hash(line, table, counter)
656657
end
657658
end
658659

659-
# Manually remove chain
660-
if %r{(\s|^)-A\s}.match?(values)
661-
values = values.sub(%r{(\s|^)-A\s}, '\1')
662-
keys << :chain
663-
end
664-
665-
# Manually remove table (used in some tests)
666-
if %r{^-t\s}.match?(values)
667-
values = values.sub(%r{^-t\s}, '')
668-
keys << :table
669-
end
670-
671-
# manually remove comments if they made it this far
672-
if %r{-m comment --comment}.match?(values)
673-
values = values.sub(%r{-m comment --comment "((?:\\"|[^"])*)"}, {})
674-
end
675-
676660
valrev = values.scan(%r{("([^"\\]|\\.)*"|\S+)}).transpose[0].reverse
677661

678662
if keys.length != valrev.length

0 commit comments

Comments
 (0)