Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(orderBy): do not try to call valueOf/toString on null #10386

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Dec 9, 2014

8bfeddb added changes to make relational operator work as it
normally would in JS --- unfortunately, this broke due to my failure to account for typeof null
being "object".

This refactoring attempts to convert object values to primitives still, in a fashion similar to
the SortCompare (and subsequently the ToString() algorithm) from ES, in order to account for null
and also simplify code to some degree.

BREAKING CHANGE:

Previously, if either value being compared in the orderBy comparator was null or undefined, the
order would not change. Now, this order behaves more like Array.prototype.sort, which by default
pushes null behind objects, due to n occurring after [ (the first characters of their
stringified forms) in ASCII / Unicode. If toString is customized, or does not exist, the
behaviour is undefined.

Closes #10385

@googlebot
Copy link

CLAs look good, thanks!

@caitp
Copy link
Contributor Author

caitp commented Dec 9, 2014

there are other ways to fix this, but this seemed the most correct. It's really hard to tell though. @petebacondarwin can you review?

{ id: 3 },
null
];
expect(orderBy(array)).toEqualData(array.sort());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course, can't rely on IE to behave similarly to other browsers here =( whelp, fixing the tests I guess.

8bfeddb added changes to make relational operator work as it
normally would in JS --- unfortunately, this broke due to my failure to account for typeof null
being "object".

This refactoring attempts to convert object values to primitives still, in a fashion similar to
the SortCompare (and subsequently the ToString() algorithm) from ES, in order to account for `null`
and also simplify code to some degree.

BREAKING CHANGE:

Previously, if either value being compared in the orderBy comparator was null or undefined, the
order would not change. Now, this order behaves more like Array.prototype.sort, which by default
pushes `null` behind objects, due to `n` occurring after `[` (the first characters of their
stringified forms) in ASCII / Unicode. If `toString` is customized, or does not exist, the
behaviour is undefined.

Closes angular#10385
@petebacondarwin
Copy link
Contributor

This seems cleaner. I guess all the tests pass in which case LGTM

@caitp
Copy link
Contributor Author

caitp commented Dec 9, 2014

alright thanks

@caitp caitp closed this in a097aa9 Dec 9, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OrderBy filter throwing an exception when property value is null
3 participants