Details
-
Improvement
-
Status: Resolved
-
Normal
-
Resolution: Fixed
-
PUP 5.5.10
Description
Original
Currently it is impossible to just pass a String to split and split by that string, for example:
split($var,'.')
won't work as the string is treated as regexp and is basically equivalent of split($var,/./)
While for dot it is trivial to escape (altho still surprising considering that's not how split function usually works in other languages), for more complex strings it is annoying at best (as there is AFAIK no "regex escaping" function in puppet.
My proposition is to either
- Make strings do not act as regexp. Types are there for a reason, if someone wants to split by regexp they should pass a regexp as argument
- Make strings be interpolated to regexp only when they start and end with / and have something inbetween (so split($var,"/./")) gets interpreted as regexp but split($var,"//") does not)
Update
Best course of action here is to add the ability to create a Regexp where all special characters are escaped. This is easily done by adding a flag to Regexp.new. Then, if the resulting string is needed (to be concatenated with other strings to form the final regexp), that can be achieved by using String.new(Regexp("...", true)) - i.e. by converting the created escaped regexp to a String.