Issue #7319 has been updated by Ben Hughes.
Status changed from Investigating to Accepted
ZOMG. This is horrible!
Thank you for the really good example code, helped me heaps.
So, if regsubst gets passed a nil/undef as an argument it gets dropped. I
hacked up regsubst.rb to provide some output and I get the following:
<pre>
[ben@paresthesia:~]% puppet apply --verbose regsubst.pp
alert: Scope(Class[main]): nothing done on this one, it's the base
alert: Scope(Class[main]):
info: We have 3 args
info: args is actually "["e", ",", "G"]"
info: Am an string
info: String
info: Target is "e"
alert: Scope(Class[main]): e
info: We have 4 args
info: args is actually "["", "e", ",", "G"]"
info: Am an string
info: String
info: Target is ""
alert: Scope(Class[main]):
info: We have 4 args
info: args is actually "["", "e", ",", "G"]"
info: Am an string
info: String
info: Target is ""
alert: Scope(Class[main]):
info: We have 3 args
info: args is actually "["joy", "bar", "G"]"
info: Am an string
info: String
info: Target is "joy"
alert: Scope(Class[main]): joy
info: Applying configuration version '1305137202'
notice: Finished catalog run in 0.02 seconds
</pre>
From:
<pre>
[ben@paresthesia:~]% cat !$
cat regsubst.pp
$myvar = 'aebec:aebec'
$splitted = split($myvar, ':')
# Intentionally getting a nil/empty/not there/ element from the array
$test = $splitted[4]
alert("nothing done on this one, it's the base")
alert($test)
# This doesn't work
$no_dq = regsubst($test, 'e', ',', 'G')
alert($no_dq)
# This works but is not the style standard way of using a single variable
$with_dq = regsubst("$test", 'e', ',', 'G')
alert($with_dq)
$foo = [ "aebec" , "aebec" , undef , undef , undef ]
$magic = regsubst( $foo[4] , 'e' , ',' , 'G' )
alert( $magic )
$split_array = split( "i am a fish" , ' ' )
$undef_element_of_array = $split_array[100000]
$missing_first_arg = regsubst( $undef_element_of_array , 'joy' , 'bar' , 'G' )
alert( $missing_first_arg )
</pre>
You can't pass/assign undef/nil to regsubst, as it makes a symbol of it. But if
you create one in a variable, say from split, it can happily get that. And then
it gets dropped, I imagine by the following lines in regsubst():
<pre>
newfunction(
:regsubst, :type => :rvalue, doc = "..."
do |args|
target, regexp, replacement, flags, lang = args
</pre>
----------------------------------------
Bug #7319: regsubst needs double quotes when variable gets assigned a
"nil/undef" from an non existent item in array.
https://projects.puppetlabs.com/issues/7319
Author: Roberto Bouza
Status: Accepted
Priority: Normal
Assignee: Ben Hughes
Category: functions
Target version:
Affected Puppet version: 2.6.4
Keywords:
Branch:
Hello,
Going through the style sheet I was modifying some classes and I hit
this, maybe a bug maybe not:
<pre>
--- test.pp ---
$myvar = 'aebec:aebec'
$splitted = split($myvar, ':')
# Intentionally getting a nil/empty/not there/ element from the array
#
$test = $splitted[4]
alert($test)
# This doesn't work
$no_dq = regsubst($test, 'e', ',', 'G')
alert($no_dq)
# This works but is not the style standard way of using a single
variable
$with_dq = regsubst("$test", 'e', ',', 'G')
alert($with_dq)
--- end test.pp ---
</pre>
<pre>
$ puppet apply test.pp
alert: Scope(Class[main]):
alert: Scope(Class[main]): e
alert: Scope(Class[main]):
</pre>
Any help will be appreciated.
Thank you.
--
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.