Skip to content
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

Properly do lexographic comparison of ascii strings #516

Merged
merged 6 commits into from
Apr 5, 2022

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Apr 4, 2022

There are two changes here to the way that assets are compared:

  1. In order to align better with how Stellar Core sorts assets (that is to say, in no special way besides the default), we rely on the actual, raw, XDR asset type (xdr.AssetType) value to distinguish based on type. The logic is still the same, but is much easier to understand since there are no convoluted branching string comparisons.

  2. JavaScript's String.prototype.localeCompare function will sort strings with lowercase letters as having lower preference to those with uppercase ones (proof: RunKit). This is not how the ASCII table sorts them, nor is it how Stellar Core will sort them as it essentially looks at the raw byte values for ordering.

For (2), we introduce asciiCompare, which hard-codes the en locale rather than leaving it system specific and also forces uppercase letters to take precedence.

Closes #515.

Copy link
Contributor

@acharb acharb left a comment

Choose a reason for hiding this comment

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

lgtm! had 1 thought non-blocking

@Shaptic Shaptic merged commit fba5529 into master Apr 5, 2022
@Shaptic Shaptic deleted the asset-sorting-fix branch April 5, 2022 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Asset.compare treats asset codes wrong
2 participants