Skip to content

fix(table): unable to sort large numbers in strings #12052

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 1 commit into from
Jul 19, 2018

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Jul 4, 2018

Fixes not being able to sort numbers, inside strings, that are greater than the MAX_SAFE_INTEGER. These changes treat these numbers as strings since JS can't compare them reliably.

Fixes #12009.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Jul 4, 2018
@crisbeto crisbeto requested a review from andrewseguin as a code owner July 4, 2018 05:19
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 4, 2018
if (_isNumberValue(value)) {
const numberValue = Number(value);

// Numbers beyond `MAX_SAFE_INTEGER` can't be compared reliably so we leave them as strings.
Copy link
Member

Choose a reason for hiding this comment

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

Is there more explanation for why they aren't compared reliably as floating point numbers?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a link to MDN which has an explanation.

@crisbeto crisbeto force-pushed the 12009/sort-large-numbers branch from 770ec44 to f067ee9 Compare July 10, 2018 19:16
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jul 10, 2018
@jelbourn
Copy link
Member

Looks like MAX_SAFE_INTEGER doesn't exist on IE and is also missing from Closure's typings

Property 'MAX_SAFE_INTEGER' does not exist on type 'NumberConstructor'.

We could just hard-code the value (since it's always the same) with a comment explaining why.

@jelbourn jelbourn added presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged and removed action: merge The PR is ready for merge by the caretaker labels Jul 12, 2018
Fixes not being able to sort numbers, inside strings, that are greater than the `MAX_SAFE_INTEGER`. These changes treat these numbers as strings since JS can't compare them reliably.

Fixes angular#12009.
@crisbeto crisbeto force-pushed the 12009/sort-large-numbers branch from f067ee9 to ae5ca19 Compare July 13, 2018 16:21
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged labels Jul 13, 2018
@crisbeto
Copy link
Member Author

I seem to have the Number.MAX_SAFE_INTEGER on IE11, but I've moved it out into a constant anyway so we don't run into Closure issues.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MatSort doesn't sort if value is a string consisting of a large numeric value
5 participants