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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wasrest[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"
andindex
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.