russplaysguitar / UnderscoreCF

An UnderscoreJS port for Coldfusion. Functional programming library.
http://russplaysguitar.github.com/UnderscoreCF/
MIT License
89 stars 38 forks source link

Calling slice with a "to" 1 value greater than the length of the array causes an error #58

Open murphydan opened 6 years ago

murphydan commented 6 years ago

Here is how to reproduce the error...

<cfset _ = new modules.underscorecf.Underscore() />

<cfscript>
writeDump(var = "hello");
myArray = [1,2,3,4];

bleh = _.slice(myArray, 1, 5);

</cfscript>

The problem is in line 874 (the 2nd line below). It should be (to >= (len + 1)) ? len + 1 (notice the >= instead of just >).

to = (!structKeyExists(arguments, 'to')) ? len + 1 :
(to > (len + 1)) ? len + 1 :
(to < 0) ? to + len + 1 :
to + 1;

It basically tries to assign the to value greater than the length of the array. If you use a value that is more than just 1 value greater (to=10 when the length of the array is 4), it all works great. It is only when the to is exactly 1 value greater than the length of the array.

I don't mind trying to help by putting in a pull request (assuming you're seeing the same thing I am). Are you still accepting pull requests? Seems like from reading through the repo that maybe tests are already failing or something?

Let me know what you think. Thanks!

russplaysguitar commented 6 years ago

Thanks for reaching out!

I'm not actively working on this library, but I'm happy to accept PRs as long as they include passing tests.

Currently, the tests are failing on newer CF platforms. This is due to a bug that is proving difficult to fix without adding a dependency on Java. See: https://github.com/russplaysguitar/UnderscoreCF/pull/54