Skip to content

Conversation

sprd-tmu
Copy link
Contributor

@sprd-tmu sprd-tmu commented Apr 4, 2024

This PR fixes a too greedy regular expression for rake syntax:hiera.

Description:
Given these keys in a common.yaml:

---
firstkey: 'one'
secondkey: 'two'
mymod::mykey: "%{lookup('firstkey')}%{lookup('secondkey')}"

This concatenates the keys 'firstkey' ('one') and 'secondkey' ('two') to 'mykey' ('onetwo').
Because of a too greedy regular expression, this leads to a warning, which shouldn't.

Expected result:

# rake syntax:hiera
---> syntax:hiera:yaml
#

Actual result:

# rake syntax:hiera
---> syntax:hiera:yaml
WARNING: data/common.yaml: Key :mymod::mykey: string after a function call but before `}` in the value
#

Explanation:
The regular expression /%{.+\('.*'\).+}/ matches %{lookup('firstkey')}%{lookup('secondkey')}, which fires the Warning.
The regular expression /%{[^}]+\('[^}]*'\)[^}\s]+}/ does not match %{lookup('firstkey')}%{lookup('secondkey')}.
It still matches %{lookup('firstkey'):3306}%{lookup('secondkey')} or any other non-whitespace character between ) and the next } in a function interpolation, which is the purpose of the Warning.

@bastelfreak
Copy link
Member

@bastelfreak bastelfreak added the bug Something isn't working label Apr 4, 2024
@sprd-tmu
Copy link
Contributor Author

sprd-tmu commented Apr 4, 2024

@bastelfreak Added tests.

@bastelfreak bastelfreak merged commit 7860b66 into voxpupuli:master Apr 4, 2024
bastelfreak added a commit to bastelfreak/puppetlabs_spec_helper that referenced this pull request Apr 4, 2024
4.1.0 had a bug in the Hiera syntax validation. This is fixed in 4.1.1.
See voxpupuli/puppet-syntax#171 for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants