Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unexpected behavior with replaceList function

Tags:

coldfusion

We recently moved from CF 10 to CF 2016 and stumbled upon the following issue:

<cfscript>

    x = "abc";
    x = replaceList(x, "ab|cd", "1|2", "|");
    writeDump(x);

    // CF 11, CF 2016
    // >> 12

    // CF 10, Railo/Lucee
    // >> 1c

    // --------------------

    x = "abc";
    x = replaceList(x, "ab,cd", "1,2", ",");
    writeDump(x);

    // CF 11, CF 2016
    // >> 1c

    // CF 10, Railo/Lucee
    // >> 1c

</cfscript>

What is going on here? Why is this change not documented by Adobe? Is it even an intended change to begin with?

Update:

Bug Report #4164200 filed with Adobe

like image 505
Alex Avatar asked Mar 07 '26 10:03

Alex


1 Answers

Short answer:

I suspect it is unintentional and would file a bug report. As a work around, try escaping the pipe symbol: replaceList(x, "ab|cd", "1|2", "\|");.

Longer answer:

Internally, this function would almost certainly use some sort of regular expression ( where pipe symbols | have a special meaning ie logical OR). My guess is that CF first uses String.split("regex") to break the two lists into arrays. Then loops through the arrays to perform the replacements.

Based on the results, CF is not escaping the pipe symbol, causing the lists to be split differently than expected. Each individual character becomes a separate element, which obviously ends up matching more than you intended ie every character in the base string.

list = "ab|cd";
writeDump(list.split("|") );

Results of split("|")

However, if you escape the pipe symbol with \, you get the expected results:

list = "ab|cd";
writeDump(list.split("\|"));

Results of split("\|")

like image 89
Leigh Avatar answered Mar 08 '26 22:03

Leigh