Bug in REFind [Lucee 5.3.8.189]

Hi,
as I saw the release of Lucee 5.3.8 I was curious if I could upgrade one of my servers to the new version.
while testing I noticed that REFind throws an error when using it with the scope="all" option.

Context
I am searching for uppercase letters in a String via REFind with the expression reg_expression="[A-Z]"

Bug
After some testing I noticed that the error only occures when the REFind does not find any matches. In Lucee 5.3.7 the result of the REFind statement is 0 in this case. As shown in my test below this also applies to string.REFind

Code

try{ local.testStr = "teststring12e"; local.testStr.reFind( reg_expression = "[A-Z]", scope = "all" ); } catch( any e ) { writeDump( '"teststring12e" FAILED' ); }
try{ reFind( reg_expression = "[A-Z]", string = "teststring12e", scope = "all" ); } catch( any e ) { writeDump( '"teststring12e" FAILED' ); }
try{ writeDump( reFind( reg_expression = "[A-Z]", string = "Teststring12e", scope = "all" ) ); } catch( any e ) { writeDump( '"Teststring12e" FAILED' ); }
try{ writeDump( reFind( reg_expression = "[A-Z]", string = "testString12e", scope = "all" ) ); } catch( any e ) { writeDump( '"testString12e" FAILED' ); }
try{ writeDump( reFind( reg_expression = "[A-Z]", string = "TestString12E", scope = "all" ) ); } catch( any e ) { writeDump( '"TestString12E" FAILED' ); }

Expected Output: None
Actual Output:

"teststring12e" FAILED
"teststring12e" FAILED

Stack Trace

lucee.runtime.exp.CasterException: Can't cast Object type [Number] to a value of type [Array] at lucee.runtime.op.Caster.toArray(Caster.java:2408) at lucee.runtime.regex.Perl5Regex.indexOfAll(Perl5Regex.java:55) at lucee.runtime.functions.string.REFind.call(REFind.java:59) at <Usage in Code>

Sincerely, Christian

OS: macOS 11.4
Java Version: 1.8.0_291
Lucee Version: 5.3.8.189

Hi Christian, I’m not getting any stack trace at all on your submitted code, becauise each line is wrapped in cftry and cfcatch, thus I only get regular outputs and dumps. What and where is exactly the error being thrown?

Hi Andreas,
I wrapped the REFind statements in try-catch to make testing easier.
If you execute the function alone you should get the stack-trace.

local.testStr = "teststring12e";
local.testStr.reFind( reg_expression = "[A-Z]", scope = "all" );

or

reFind( reg_expression = "[A-Z]", string = "teststring12e", scope = "all" );

Throws an exception on in my environment.

1 Like

But don’t these type of expressions return only simple values instead of returning variables assigned to values (e.g. like a++)'? I thought these need to have additional assignements, thus the error, or not?

Ahhh … i forgot to welcome you to our community!!! :smiley:

1 Like

file a bug, good catch!

there’s a problem with named arguments

1 Like

Already a bug filed with the same issue. [LDEV-3532] - Lucee

1 Like

Thanks @all

1 Like