Skip to content

Commit 0512526

Browse files
committed
(PUP-11315) Allow resource attributes named "plan" and "apply"
Previously, using either of these keywords as resource attribute names within an apply() block in a plan would fail. That happened because they weren't included in the `keyword` rule. This was only a problem when running in a plan, because those keywords only exist when the `tasks` setting is set. In normal Puppet operation, they aren't lexed as special tokens at all, so they didn't need to be in the `keyword` rule to function properly. We now add them to the `keyword` rule regardless of whether they are actually lexed as keywords, which works fine in both cases.
1 parent b5e3d4e commit 0512526

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

lib/puppet/pops/parser/egrammar.ra

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,8 @@ keyword
919919
| CONSUMES
920920
| PRODUCES
921921
| SITE
922+
| PLAN
923+
| APPLY
922924

923925
nil
924926
: { result = nil}

spec/unit/pops/parser/parse_containers_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106

107107
context 'it should allow keywords as attribute names' do
108108
['and', 'case', 'class', 'default', 'define', 'else', 'elsif', 'if', 'in', 'inherits', 'node', 'or',
109-
'undef', 'unless', 'type', 'attr', 'function', 'private'].each do |keyword|
109+
'undef', 'unless', 'type', 'attr', 'function', 'private', 'plan', 'apply'].each do |keyword|
110110
it "such as #{keyword}" do
111111
expect { parse("class x ($#{keyword}){} class { x: #{keyword} => 1 }") }.to_not raise_error
112112
end
@@ -178,7 +178,7 @@
178178

179179
context 'it should allow keywords as attribute names' do
180180
['and', 'case', 'class', 'default', 'define', 'else', 'elsif', 'if', 'in', 'inherits', 'node', 'or',
181-
'undef', 'unless', 'type', 'attr', 'function', 'private'].each do |keyword|
181+
'undef', 'unless', 'type', 'attr', 'function', 'private', 'plan', 'apply'].each do |keyword|
182182
it "such as #{keyword}" do
183183
expect {parse("define x ($#{keyword}){} x { y: #{keyword} => 1 }")}.to_not raise_error
184184
end

spec/unit/pops/validator/validator_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ def with_environment(environment, env_params = {})
432432
expect(acceptor.error_count).to eql(0)
433433
end
434434

435+
it 'allows apply to be used as a resource attribute name' do
436+
acceptor = validate(parse('apply("foo.example.com") { sometype { "resourcetitle": apply => "applyvalue" } }'))
437+
expect(acceptor.error_count).to eql(0)
438+
end
439+
435440
it 'accepts multiple arguments' do
436441
acceptor = validate(parse('apply(["foo.example.com"], { "other" => "args" }) { }'))
437442
expect(acceptor.error_count).to eql(0)

0 commit comments

Comments
 (0)