-
Notifications
You must be signed in to change notification settings - Fork 126
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
Fix sort-by with null values #377
Conversation
`aValue.toLowerCase` throws an error if `null` is not explicitly handled: `Uncaught TypeError: Cannot read property 'toLowerCase' of null`
Test that undefined values are sorted, not ignored
this.set('array', [ | ||
{ name: 'c' }, | ||
{ name: 'a' }, | ||
{ name: undefined }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One behaviour of sort was to remove undefined values. We would probably want to keep this sort of test around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, not sure I understand -- what do you mean by "remove undefined values"?
This merely changes the test to assert that the undefined value is at the end of the resulting array. At present the test will assert "abc"
regardless of what position undefined
is in the resulting array since undefined renders nothing, so textContent
will be abc
no matter what
You could change sort-by to sort undefined first, sort undefined last, remove undefineds or even randomly add a bunch of undefineds, and this test will always pass before this change, so it doesn't really test anything at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See original assertion...
assert.equal(find('*').textContent.trim(), 'abc');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I've seen that and I still don't understand. I've been relooking the test over and over again, could you please elaborate in more detail?
If sort-by
returns any of these results, textContent
is still 'abc'
:
{{#each (array "a" "b" "c") as |str|}}{{str}}{{/each}}
textContent === 'abc'
{{#each (array "a" "b" undefined "c") as |str|}}{{str}}{{/each}}
textContent === 'abc'
{{#each (array undefined "a" undefined undefined "b" undefined "c" undefined) as |str|}}{{str}}{{/each}}
textContent === 'abc'
I'm not sure what the original assertion is testing for?
Put another way: what result of sort-by
would cause this assertion to fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We simply want the original test around. The test assertions you added should be in a new test
Is there anything I can do to help get this merged? This is a production issue for us requiring us to stay locked to 4.2.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
e7a8f01 breaks
sort-by
when a value isnull
sincenull.toLowerCase
throws the following:I suppose the truthy checks were required after all to prevent that
I'm not sure what the ideal handling of null values should be, so this PR is just my take:
I believe null values should be sorted last as well since doing comparisons to null can lead to inconsistent sorting:
However, this doesn't sort between
undefined
andnull
-- not sure if that's a problem.Also made a change to the
'ignores undefined values sorting'
test case since undefined values should be expected to be sorted last now, not ignored. The way the test was written, it would never fail regardless of the position the undefined value was in