Jira (PUP-10178) split function shouldn't coerce strings to regex

11 views
Skip to first unread message

Ben Ford (JIRA)

unread,
Dec 17, 2019, 2:18:04 PM12/17/19
to puppe...@googlegroups.com
Ben Ford created an issue
 
Puppet / Bug PUP-10178
split function shouldn't coerce strings to regex
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2019/12/17 11:17 AM
Priority: Normal Normal
Reporter: Ben Ford

The split() function turns strings into regexes internally, which is not intuitive and leads to surprising results.

$ puppet apply -e 'notice("2.6.3".split("."))'
Notice: Scope(Class[main]): []
Notice: Compiled catalog for nyx.local in environment production in 0.03 seconds
Notice: Applied catalog in 0.02 seconds 

 
Of note, this is not what Ruby does:

$ ruby -e "puts '2.6.3'.split('.').inspect"
["2", "6", "3"]

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Dec 18, 2019, 6:28:03 AM12/18/19
to puppe...@googlegroups.com
Henrik Lindberg commented on Bug PUP-10178
 
Re: split function shouldn't coerce strings to regex

This is for historic reasons - the split function has been doing this since the very start. If this is changed it will need to be changed on a major version boundary as results will be different. The change would need some kind of deprecation - which is tricky as it would be for every call to split where it is given a string. Users would need to convert to regexp to avoid the deprecation, then once the major release takes place the function would stop turning strings into regexp.

Alternatively, an option (use_as_string Bool) could be added to the function to tell it what to do - i.e. without option it would be backwards compatible. This would be trivial to add and can be added in any version.

Rob Braden (JIRA)

unread,
Jan 13, 2020, 12:53:04 PM1/13/20
to puppe...@googlegroups.com

Nick Walker (Jira)

unread,
Oct 2, 2020, 1:07:05 PM10/2/20
to puppe...@googlegroups.com
Nick Walker commented on Bug PUP-10178
 
Re: split function shouldn't coerce strings to regex

Ben Ford what's the play here?  I think we shouldn't change the default behavior so we don't break people relying on the weird behavior.  

So do we just close this or should we reword this to be about augmenting the function or adding a new one to accomplish whatever needs to be accomplished?

This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Maggie Dreyer (Jira)

unread,
Nov 9, 2020, 5:22:03 PM11/9/20
to puppe...@googlegroups.com

While not intuitive, if this is documented, it seems easy to work around. I think we're unlikely to fix this either way, so I'm going to close this. Please reopen if that's not true.

Maggie Dreyer (Jira)

unread,
Nov 9, 2020, 5:23:03 PM11/9/20
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages