Unncessarily restrictive arg checking on directoryList() callback

Description

Repro attached, but also here for easy inspection:

<cfscript> a = ["a", "b", "c"] ; result = arrayFilter(a, function(v,i,a,x){ writeDump(arguments); return true; }); writeDump(result); result = directoryList(expandPath("."), true, "array", function(f,g){ writeDump(arguments); return true; }); writeDump(result); </cfscript>

The first example is a control. Note how my callback function for arrayFilter() can have additional arguments that are not expected.

However the second example, using directoryList() raises an exception because the function I'm using for the callback takes an additional argument.

It is in conflict with how CFML's UDFs work to error based solely on the signature of the method. You should not be doing this sort of argumet-count verification. Just let the function run... it'll error all by itself if it so transpires it actually needed that additional argument.

Bear in mind that callbacks are not necessarily defined inline & use-time; it's entirely possible to use an already existing function... one that might have a default on that argument, or it's not used in the situation it'll be used at runtime, or [whatever]. Don't second-guess this sort of thing.

Environment

None

Attachments

1
  • 06 Jun 2015, 05:30 pm

Activity

Show:

Zac Spitzer 29 September 2023 at 08:15

cleaned up test, removed pdf as not not needed, enabled the passing tests, as test coverage is always good

https://github.com/lucee/Lucee/pull/2250

Zac Spitzer 29 September 2023 at 08:04

stack trace is

at lucee.commons.io.res.util.UDFFilterSupport.<init>(UDFFilterSupport.java:41) [java] [script] at lucee.commons.io.res.util.UDFFilter.<init>(UDFFilter.java:36) [java] [script] at lucee.commons.io.res.util.UDFFilter.createResourceAndResourceNameFilter(UDFFilter.java:84) [java] [script] at lucee.commons.io.res.util.UDFFilter.createResourceAndResourceNameFilter(UDFFilter.java:79) [java] [script] at lucee.runtime.functions.file.DirectoryList._call(DirectoryList.java:56)

Pothys - MitrahSoft 18 November 2016 at 15:27
Edited

I've added the test cases for this ticket, In Lucee directoryList() with callback function having restriction on arguments.It accepts only a single argument.

Pull Request: https://github.com/lucee/Lucee/pull/99

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 6 June 2015 at 17:35
Updated 29 September 2023 at 08:15