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

Editorial: Fix off-by-1 error in PartitionPattern #392

Merged
merged 1 commit into from
Jan 8, 2020

Conversation

longlho
Copy link
Collaborator

@longlho longlho commented Nov 27, 2019

Right now after the loop finishes, the remainder is
pattern.substring(nextIndex + 1, len) (bc it's exclusive) but should
be pattern.substring(nextIndex, len) instead since nextIndex is
already set to endIndex + 1 in the loop.

Take AA{0}BB as an example, after the loop finishes:

  • beginIndex = -1
  • endIndex = 4
  • nextIndex = 5

so pattern.substring(5, 7) yields BB (correct) vs the old behavior
would just yield B

Reference impl: https://github.com/formatjs/formatjs/blob/master/packages/intl-utils/src/polyfill-utils.ts#L220
Reference test: https://github.com/formatjs/formatjs/blob/master/packages/intl-utils/tests/polyfill-utils.ts

@Ms2ger
Copy link
Contributor

Ms2ger commented Nov 27, 2019

Nice, thanks for catching that. It looks like PartitionNumberPattern was correct, and PartitionDateTimePattern was wrong, and I copied the wrong one in #366. The bug appears to date back to #100 from 2016.

@longlho
Copy link
Collaborator Author

longlho commented Nov 27, 2019

Gotcha, thanks for the context!

Copy link

@spectranaut spectranaut left a comment

Choose a reason for hiding this comment

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

Good catch!

Right now after the loop finishes, the remainder is
`pattern.substring(nextIndex + 1, len)` (bc it's exclusive) but should
be `pattern.substring(nextIndex, len)` instead since `nextIndex` is
already set to `endIndex + 1` in the loop.

Take `AA{0}BB` as an example, after the loop finishes:
- beginIndex = -1
- endIndex = 4
- nextIndex = 5

so `pattern.substring(5, 7)` yields `BB` (correct) vs the old behavior
would just yield `B`
@sffc sffc added the has consensus Has consensus from TC39-TG2 label Jan 8, 2020
@sffc
Copy link
Contributor

sffc commented Jan 8, 2020

Has consensus according to December ECMA-402.

What further action is required on this Editorial PR?

@leobalter leobalter changed the title Normative: Fix off-by-1 error in PartitionPattern Editorial: Fix off-by-1 error in PartitionPattern Jan 8, 2020
@leobalter
Copy link
Member

I'm renaming the PR to reflect it's fixing a typo mostly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has consensus Has consensus from TC39-TG2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants