fix(lt-LT,lv-LV): guard scale ceilings in the Baltic pair#359
Merged
Conversation
Both crashed past their scale vocabulary: cardinal/currency threw a raw TypeError (indexing a missing [singular, few/plural, genitive] form array) and ordinal returned "". Now throw a clean RangeError. Per-form ceilings derived from each table: - Cardinal/currency: SCALE_FORMS (9 entries) -> 10^((len+1)*3) = 10^30. - Ordinal: shorter ORDINAL_SCALES (4 entries) -> 10^((len+1)*3) = 10^15. Entry-point pattern; decimal guarded (integer-spelled fractions). Both tables are already module-scope. 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 is part of the ongoing “fix-then-gate” hardening series: it adds scale-ceiling guards for Latvian (lv-LV) and Lithuanian (lt-LT) so that values beyond each locale’s scale vocabulary reliably throw a consistent RangeError (via tooLargeError) instead of crashing or producing malformed output.
Changes:
- Add derived magnitude ceilings for cardinal/currency (from
SCALE_FORMS) and ordinal (fromORDINAL_SCALES) in both Baltic locale implementations. - Enforce the ceilings at public entry points (
toCardinal,toOrdinal,toCurrency), including guarding the decimal significant digits where decimals are spelled via the scale builder.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/lv-LV.js | Introduces MAX_* ceilings derived from scale tables and throws tooLargeError(...) at public entry points to prevent out-of-range crashes/malformed output. |
| src/lt-LT.js | Mirrors the same ceiling-derivation and entry-point guards for Lithuanian, covering cardinal/currency/ordinal and scale-spelled decimals. |
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.
Eleventh in the fix-then-gate series. Lithuanian + Latvian —
TypeErrorcrashers (like Serbian).What fuzzing found
Past their scale vocabulary both crashed: cardinal/currency threw a raw
TypeError(indexing a missing[singular, few/plural, genitive]form array) and ordinal returned"". Now all throw a cleanRangeError.SCALE_FORMS(9 entries)ORDINAL_SCALES(4 entries)Fix
Entry-point pattern; ceilings derived from each table (
(length + 1) * 3, units separate). Decimal guarded (integer-spelled fractions). Both scale tables were already module-scope, so no hoisting needed.Verification
Per locale: well-formed string or
RangeErroracross±10⁴⁰; integer/ordinal/decimal boundaries confirmceil−1ok /ceilthrows (cardinal 10³⁰, ordinal 10¹⁵). Existing fixtures green, lint clean, 269 tests.🤖 Generated with Claude Code