Skip to content

fix(lt-LT,lv-LV): guard scale ceilings in the Baltic pair#359

Merged
TylerVigario merged 1 commit into
mainfrom
fix/baltic-scale-ceilings
Jun 4, 2026
Merged

fix(lt-LT,lv-LV): guard scale ceilings in the Baltic pair#359
TylerVigario merged 1 commit into
mainfrom
fix/baltic-scale-ceilings

Conversation

@TylerVigario
Copy link
Copy Markdown
Collaborator

Eleventh in the fix-then-gate series. Lithuanian + Latvian — TypeError crashers (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 clean RangeError.

form ceiling table
cardinal / currency 10³⁰ SCALE_FORMS (9 entries)
ordinal 10¹⁵ 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 RangeError across ±10⁴⁰; integer/ordinal/decimal boundaries confirm ceil−1 ok / ceil throws (cardinal 10³⁰, ordinal 10¹⁵). Existing fixtures green, lint clean, 269 tests.

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 4, 2026 14:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 (from ORDINAL_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.

@TylerVigario TylerVigario merged commit 2207d12 into main Jun 4, 2026
8 checks passed
@TylerVigario TylerVigario deleted the fix/baltic-scale-ceilings branch June 4, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants