Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix too greedy regular expression #171

Merged
merged 2 commits into from
Apr 4, 2024
Merged

fix too greedy regular expression #171

merged 2 commits into from
Apr 4, 2024

Conversation

tmu-sprd
Copy link
Contributor

@tmu-sprd tmu-sprd 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
@tmu-sprd
Copy link
Contributor Author

tmu-sprd commented Apr 4, 2024

@bastelfreak Added tests.

@bastelfreak bastelfreak merged commit 7860b66 into voxpupuli:master Apr 4, 2024
10 checks passed
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