fix(nb-NO,sv-SE,fi-FI): guard scale ceilings in the Nordic group#361
Merged
Conversation
Three distinct languages, each with its own ceiling (verified individually): - nb-NO: 10^30 (SCALES indexed [scaleIndex-2], 8 entries). Decimal guarded. - sv-SE: 10^27 (SCALES indexed [scaleIndex-1] from 'tusen', 8 entries). Decimal guarded. - fi-FI: 10^18 (SCALES [scaleIndex-2], 4 entries). NO decimal guard — Finnish reads the fraction digit-by-digit (40-digit decimal still converts). All three: ordinal (cardinal + suffix) and currency build on the cardinal, so a single MAX_CARDINAL guards all forms. Entry-point pattern; ceiling derived from each SCALES table. Verified per locale (well-formed or RangeError; integer/ordinal/decimal boundaries); full suite green (269). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR continues the “fix-then-gate” series by adding scale-ceiling enforcement for three Nordic locales so that values at/above each language’s largest supported magnitude throw a uniform RangeError (via tooLargeError) instead of producing malformed output.
Changes:
- Add per-locale
MAX_CARDINAL/MAX_CARDINAL_EXPONENTconstants derived from each locale’sSCALEStable. - Add entry-point guards in
toCardinal,toOrdinal, andtoCurrencyto throwtooLargeError(...)when out of range (and additionally guard the decimal significant digits for nb-NO and sv-SE where decimals use the scale builder). - Import and use the shared
tooLargeErrorhelper in the updated locales.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/sv-SE.js | Adds a 10^27 ceiling derived from SCALES and enforces it at public entry points (including decimal significant digits). |
| src/nb-NO.js | Adds a 10^30 ceiling derived from SCALES and enforces it at public entry points (including decimal significant digits). |
| src/fi-FI.js | Adds a 10^18 ceiling derived from SCALES and enforces it at public entry points (integer only; decimals are per-digit and intentionally unguarded). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Thirteenth in the fix-then-gate series. Three Nordic languages, each verified individually (distinct ceilings).
[scaleIndex-2], 8 entries[scaleIndex-1]fromtusen, 8 entries[scaleIndex-2], 4 entriesAll three: ordinal (cardinal + suffix) and currency build on the cardinal, so one
MAX_CARDINALguards every form. fi-FI reads its fraction digit-by-digit, so a long decimal has no ceiling and is correctly not guarded (a 40-digit decimal still converts); nb/sv spell the fraction viaintegerToWords, so they are.Verification
Per locale: well-formed string or
RangeErroracross±10⁴⁰; integer/ordinal/decimal boundaries confirmceil−1ok /ceilthrows. Existing fixtures green, lint clean, 269 tests.🤖 Generated with Claude Code