Skip to content

Core: Don't rely on splice being present on input #4986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 24, 2022
Merged

Conversation

bubbatls
Copy link
Contributor

Without this fix it does that

TypeError: results.splice is not a function
at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12)
at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27)
at gocusihafe.js:3:4

Reproduced here:
https://jsbin.com/gocusihafe/1/edit?html,css,js,console,output

Summary

Checklist

Sorry, something went wrong.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 17, 2021

CLA Signed

The committers are authorized under a signed CLA.

@timmywil
Copy link
Member

Thanks for opening a pull request! It seems we forgot to change our use of splice when removing it from the jQuery object. We did take care of sort and push, just not splice. I'm surprised our tests didn't catch this, but we're going to need to add a test.

Something like the case in the jsbin will work fine to get duplicates on the jQuery object (i.e. jQuery('body div').find('div')). A relatively pointless call to find as it won't find anything new, but it does the job here of inserting duplicates. That said, there are a lot of divs on the test page, so it would be good to limit it to smaller selection. Something like jQuery("#moretests div").find("div") should work.

Also, splice should be its own var file, just like with sort

Thanks!

@mgol
Copy link
Member

mgol commented Dec 29, 2021

@bubbatls Hey, are you interested in addressing Timmy's concerns?

@mgol
Copy link
Member

mgol commented Jan 5, 2022

@bubbatls Ping. This looks like an issue we'd like to see fixed but to land your PR we need to have Timmy's concerns addressed. If you don't have time for this, please let us know and we'll likely fix this by ourselves.

@bubbatls
Copy link
Contributor Author

bubbatls commented Jan 5, 2022

I'm sorry, I was in holiday and after holidays there is a lot of work to do...
Yes I could fix this using your kind of var files, just let me few days.

Thanks

@mgol
Copy link
Member

mgol commented Jan 5, 2022

@bubbatls Sure, no problem. Let us know if you hit any roadblocks.

Fixed by creating a var file for splice as for other Array methods
Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good now but we still need a test. Can you add one?

@timmywil BTW, I think we can have a simpler & more direct test:

jQuery.uniqueSort( { 0: div, 1: div, length: 2 } );

where div is a test div appended to #qunit-fixture. What do you think? Or maybe we can add both test cases.

@bubbatls
Copy link
Contributor Author

yes, the test you write is the most unit one about this issue, and the method name is uniqueSort so, checking the "unique" is completely relevant.

But I agree that another one covering more code by doing the .find('div').find('div') is worth being written for potential future regression.

This test should be written in the test/unit/selector.js file?

@mgol
Copy link
Member

mgol commented Jan 11, 2022

This test should be written in the test/unit/selector.js file?

Yes, the both tests should be written in test/unit/core.js test/unit/selector.js but in separate QUnit.test blocks as they're testing two different things.

EDIT: I made a typo and I mentioned test/unit/core.js instead of the proper test/unit/selector.js; I fixed the comment now.

@bubbatls
Copy link
Contributor Author

I'm sorry but I spend some time to try to understand how to run the tests before modifying anything. But I have always the error :
test/data/qunit-fixture.js net::ERR_ABORTED 404 (Not Found)
And I don't understand what I'm doing wrong.

@mgol
Copy link
Member

mgol commented Jan 17, 2022

How are you running the tests?

You need to build before running the tests as the build process creates a few test files and also builds jQuery and the built version is what gets tested by default. Run npm run build before running the tests.

There was a bug in the test
the input was modified to the good result before the second way of testing with not true Array object.
@bubbatls
Copy link
Contributor Author

Thank you, I'm sorry I'm new to npm. In fact there was a bug in an existing unit test for all that. So I've fixed it

Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some style nits but otherwise looks good, thanks! It's nice you found an existing broken test.

@mgol mgol changed the title Fix splice on non Array Core: Don't rely on splice being present on input Jan 24, 2022
@mgol mgol added Core Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Jan 24, 2022
@mgol mgol added this to the 4.0.0 milestone Jan 24, 2022
Copy link
Member

@timmywil timmywil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. Thanks for the tests.

@mgol mgol merged commit 9c6f64c into jquery:main Jan 24, 2022
@mgol mgol removed the Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. label Jan 24, 2022
@bubbatls bubbatls deleted the patch-1 branch January 25, 2022 06:32
@bubbatls
Copy link
Contributor Author

Nice! thanks you all :)

mgol added a commit to mgol/jquery that referenced this pull request Sep 8, 2022
Without this fix calling `jQuery.uniqueSort` on an array-like can result in:

TypeError: results.splice is not a function
    at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12)
    at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27)
    at gocusihafe.js:3:4

Ref jquerygh-4986
mgol added a commit to mgol/jquery that referenced this pull request Sep 12, 2022
Without this fix calling `jQuery.uniqueSort` on an array-like can result in:

TypeError: results.splice is not a function
    at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12)
    at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27)
    at gocusihafe.js:3:4

Ref jquerygh-4986
mgol added a commit to mgol/jquery that referenced this pull request Sep 19, 2022
Without this fix calling `jQuery.uniqueSort` on an array-like can result in:

TypeError: results.splice is not a function
    at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12)
    at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27)
    at gocusihafe.js:3:4

Ref jquerygh-4986
mgol added a commit to mgol/jquery that referenced this pull request Sep 21, 2022
Without this fix calling `jQuery.uniqueSort` on an array-like can result in:

TypeError: results.splice is not a function
    at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12)
    at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27)
    at gocusihafe.js:3:4

Ref jquerygh-4986
mgol added a commit to mgol/jquery that referenced this pull request Oct 3, 2022
Without this fix calling `jQuery.uniqueSort` on an array-like can result in:

TypeError: results.splice is not a function
    at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12)
    at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27)
    at gocusihafe.js:3:4

Ref jquerygh-4986
mgol added a commit to mgol/jquery that referenced this pull request Oct 4, 2022
Without this fix calling `jQuery.uniqueSort` on an array-like can result in:

TypeError: results.splice is not a function
    at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12)
    at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27)
    at gocusihafe.js:3:4

Ref jquerygh-4986
mgol added a commit to mgol/jquery that referenced this pull request Nov 17, 2022
Without this fix calling `jQuery.uniqueSort` on an array-like can result in:

TypeError: results.splice is not a function
    at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12)
    at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27)
    at gocusihafe.js:3:4

Ref jquerygh-4986
mgol added a commit to mgol/jquery that referenced this pull request Dec 1, 2022
Without this fix calling `jQuery.uniqueSort` on an array-like can result in:

TypeError: results.splice is not a function
    at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12)
    at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27)
    at gocusihafe.js:3:4

Ref jquerygh-4986
mgol added a commit to mgol/jquery that referenced this pull request Dec 13, 2022
Without this fix calling `jQuery.uniqueSort` on an array-like can result in:

TypeError: results.splice is not a function
    at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12)
    at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27)
    at gocusihafe.js:3:4

Ref jquerygh-4986
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants