From ca1720729ce991ab04064ad3723d4189bbfbf72b Mon Sep 17 00:00:00 2001 From: Tino Mueller Date: Thu, 4 Apr 2024 10:14:21 +0200 Subject: [PATCH 1/2] fix too greedy regular expression --- lib/puppet-syntax/hiera.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-syntax/hiera.rb b/lib/puppet-syntax/hiera.rb index 2a8fdfe..d96f43d 100644 --- a/lib/puppet-syntax/hiera.rb +++ b/lib/puppet-syntax/hiera.rb @@ -122,7 +122,7 @@ def check(filelist) # You can do string concatenation outside of {}: # "%{lookup('this_is_ok')}:3306" def check_broken_function_call(element) - 'string after a function call but before `}` in the value' if element.is_a?(String) && /%{.+\('.*'\).+}/.match?(element) + 'string after a function call but before `}` in the value' if element.is_a?(String) && /%{[^}]+\('[^}]*'\)[^}\s]+}/.match?(element) end # gets a hash or array, returns all keys + values as array From 9862f2722b2144684dd0674f17c289b6c2e95700 Mon Sep 17 00:00:00 2001 From: Tino Mueller Date: Thu, 4 Apr 2024 11:10:52 +0200 Subject: [PATCH 2/2] add tests for concatenated function interpolations, adjust rubocop config for added tests --- .rubocop_todo.yml | 4 ++-- spec/fixtures/hiera/hiera_badkey.yaml | 2 ++ spec/puppet-syntax/hiera_spec.rb | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bdbbf18..5d8fd70 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -86,7 +86,7 @@ RSpec/DescribedClass: # Offense count: 7 # Configuration parameters: CountAsOne. RSpec/ExampleLength: - Max: 16 + Max: 17 # Offense count: 4 # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. @@ -100,7 +100,7 @@ RSpec/FilePath: # Offense count: 29 RSpec/MultipleExpectations: - Max: 10 + Max: 11 # Offense count: 30 # Configuration parameters: EnforcedStyle, IgnoreSharedExamples. diff --git a/spec/fixtures/hiera/hiera_badkey.yaml b/spec/fixtures/hiera/hiera_badkey.yaml index 9e81278..38449a3 100644 --- a/spec/fixtures/hiera/hiera_badkey.yaml +++ b/spec/fixtures/hiera/hiera_badkey.yaml @@ -3,6 +3,7 @@ this_is_ok: 0 this_is_ok::too: 0 th1s_is_ok::two3: 0 :eventhis: 0 +this_is_ok::concat_func: "%{lookup('foo')}%{lookup('bar')}" typical:typo::warning1: true ::notsotypical::warning2: true @@ -15,3 +16,4 @@ this_is::warning7: - "%{lookup('foobar'):3306}" this_is::warning8: foo: "%{lookup('foobar'):3306}" +this_is::warning9: "%{lookup('foo'):3306}%{lookup('bar')}" diff --git a/spec/puppet-syntax/hiera_spec.rb b/spec/puppet-syntax/hiera_spec.rb index 1436fbc..91fc4ad 100644 --- a/spec/puppet-syntax/hiera_spec.rb +++ b/spec/puppet-syntax/hiera_spec.rb @@ -29,7 +29,7 @@ it 'returns warnings for invalid keys' do hiera_yaml = 'hiera_badkey.yaml' - examples = 8 + examples = 9 files = fixture_hiera(hiera_yaml) res = subject.check(files) (1..examples).each do |n| @@ -44,6 +44,7 @@ expect(res[5]).to match('Key :this_is::warning6: string after a function call but before `}` in the value') expect(res[6]).to match('Key :this_is::warning7: string after a function call but before `}` in the value') expect(res[7]).to match('Key :this_is::warning8: string after a function call but before `}` in the value') + expect(res[8]).to match('Key :this_is::warning9: string after a function call but before `}` in the value') end it 'returns warnings for bad eyaml values' do