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

Fixing bug that only allowed <= 9 formatting arguments #39

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

benrr101
Copy link

Description: While working on a derivative of this library, I noticed that the regex replace method for formatting localized strings was behaving strangely with a large number of formatting arguments. The format method uses the String.prototype.replace with a regular expression and a replacer function. The original signature of the replacer function was (match, rest) and the index of the formatting argument to use was rest[0]. According to the docs each capture group of the regular expression is exposed as its own string argument to the replacer function. As such in the case of {10}, rest would be "10" and index would be calculated to be "1". Meaning it's impossible to use >9 formatting arguments with the current implementation.

The proposed solution is to remove the separate assignment of index and instead use the capture group value in its entirety as the index.

Testing: I ran this code manually in my derivative project and it works successfully. Since there are no unit tests for the formatter, I was unable to test the formatter with unit tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant