Issue #9450 has been updated by Henrik Lindberg.
It is not really possible to generally expand variables inside a regular
expression that way - as a $ has significance inside a regular expression.
It would be possible to exploit that $ means "end of input", and that the /$a/
is special in that, nothing can be matched after the "end of input".
Another solution would be to relax the =~ operator (it now only accepts a
literal regular expression on the RHS. I can imagine a function that constructs
a regular expression pattern. The above example would then be written:
`if $bar =~ pattern($foo)` or sweetened to `if $bar =~ $foo` (i.e. compile
content of $foo as pattern). This makes it possible to also use interpolation
etc. to construct the pattern `if $bar =~ "${foo}[${acceptable_chars}]".
The problems regarding recognition of variables inside the regular expression
is mainly a lexical one. There is already significant problems recognizing the
regular expression as it clashes with division / - thus, it may only appear in
certain well defined places where a division may not.
It would be possible to allow support other ways to construct literal regular
expressions (ruby has several alternatives), but it is really sufficient to
just have a function that does this provided that the expressions that accept a
literal regexp are relaxed to match against an expression producing a regexp.
To summarize - I propose:
* operator =~ compiles its RHS to a regexp if it does not evaluate to one
already
* a regexp function constructs a regexp out of its argument(s) with the same
semantics as the compilation of the =~ RHS evaluation
----------------------------------------
Bug #9450: variables embedded in regexps are not expanded
https://projects.puppetlabs.com/issues/9450#change-71105
Author: Steve Shipway
Status: Accepted
Priority: Normal
Assignee:
Category: language
Target version:
Affected Puppet version: 2.6.8
Keywords: regexp
regular expression
variable
Branch:
This doesn't define the notify resource:
<pre>
$foo = "bar"
$bar = "bar"
if $bar =~ /$foo/ {
notify { bar: message=>"BAR"; }
}
</pre>
It seems that variables within regexps are not being expanded. This is a
problem for us as we're trying to define new resources that check facts for
parameterised content via a regexp.
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-bugs?hl=en.