Skip to content

Commit 3e72ec0

Browse files
committed
(PUP-11515) Negative Lookbehind Regex Causes Duplicate Node
Before this commit, two nodes could collide due to the lookaround Regex pattern. This issue arose because the regex was converted to a regular string by ignoring characters other than a-z, 0-9, _, and -. For example, /(?<!a)sync/ was converted to "__node_regexp__async," and /async/ was also converted to "__node_regexp__async," causing an error that the node was already defined. To prevent such duplication, this commit removes the lookarround pattern from the regex at the end, ensuring a unique string in case of lookarround pattern conflict. For example, /(?<!a)sync/ will converted to "__node_regexp__sync" removing (?<!a) while converting to the string.
1 parent a812d7c commit 3e72ec0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: lib/puppet/resource/type.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def instantiate_resource(scope, resource)
196196

197197
def name
198198
if type == :node && name_is_regex?
199-
"__node_regexp__#{@name.source.downcase.gsub(/[^-\w:.]/, '').sub(/^\.+/, '')}"
199+
"__node_regexp__#{@name.source.downcase.gsub(/\(\?[^)]*\)/,'').gsub(/[^-\w:.]/, '').sub(/^\.+/, '')}"
200200
else
201201
@name
202202
end

Diff for: spec/integration/parser/node_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ class foo {
8585
end.not_to raise_error
8686
end
8787

88+
it 'does not raise an error with 2 regex node names are the same due to lookarround pattern' do
89+
expect do
90+
compile_to_catalog(<<-MANIFEST, Puppet::Node.new("async"))
91+
node /(?<!a)sync/ { }
92+
node /async/ { }
93+
MANIFEST
94+
end.not_to raise_error
95+
end
96+
8897
it 'errors when two nodes with regexes collide after some regex syntax is removed' do
8998
expect do
9099
compile_to_catalog(<<-MANIFEST)

0 commit comments

Comments
 (0)