Skip to content

fix(table-cells): parse currency input in linear time - #10316

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/table-cells-currency-redos
Nov 22, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/table-cells-currency-redos

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • parseCurrencyInput backtracked quadratically on crafted cells (CodeQL js/polynomial-redos); table imports and coercion run it per cell on the server, so one long cell could stall the event loop for seconds
  • CURRENCY_MARKER_PREFIX: whitespace runs on both sides of an optional sign split ambiguously → the sign and its trailing whitespace are one optional group (^\s*(?:([+-])\s*)?…), callback returns sign ?? ''
  • CURRENCY_MARKER_SUFFIX: unanchored with a leading whitespace run, so replace rescanned the run from every start → drop the whitespace runs and match against trimEnd(); the whitespace left before the marker is stripped with every other space right after
  • AMOUNT_SHAPE: overlapping [\d.,]*\d[\d.,]* → [.,]*\d[\d.,]* (same language, disjoint runs)
  • [\s  ] → \s (\s and trimEnd already cover U+00A0/U+202F); no length cap, no behaviour change
  • Other regexes in packages/table-cells/src checked and measured: all linear (ttl.ts's /0+$/ runs on at most 6 chars)

Type of Change

  • Bug fix

Testing

  • Equivalence (one-off script, old vs new): 0 differences over 550k inputs (test corpus, Intl output across 40 locales × 21 currencies × 4 displays × 2 signs, random and structured combos of digits, .,'’, whitespace incl. U+00A0/U+202F, signs incl. U+2212, parens, symbols, ISO codes, kr/zł/R$, letters, e/E) × 8 currency codes on both Bun and Node, plus every string up to length 6 over a 14-char alphabet × 3 codes (24.3M comparisons)
  • Linearity: new expectLinearGrowth cases in currency.test.ts fail on the old code (growth ratios 55–91 vs the 20 limit) and pass on the new; reverting each regex alone turns its own case red. At 40k chars the old code took 1–7s per cell, the new under 1ms
  • table-cells, workspace-code kinds, and apps/sim table import/coercion/column-type tests; lint, type-check, check:audits, check:test-types, block-registry check, root bun run test (one unrelated workflow-code scaling flake at 20.5, green on rerun)

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Three regexes in parseCurrencyInput backtracked quadratically on crafted
cells, and table imports and coercion run it per cell on the server.

- CURRENCY_MARKER_PREFIX: whitespace runs on both sides of an optional
  sign split ambiguously; the sign and its trailing whitespace are now one
  optional group.
- CURRENCY_MARKER_SUFFIX: unanchored with a leading whitespace run, so
  replace rescanned the run from every start; it now matches the marker
  against the right-trimmed string.
- AMOUNT_SHAPE: overlapping [\d.,]*\d[\d.,]*; the run before the first
  digit now admits only separators.
@waleedlatif1
waleedlatif1 requested a review from a team as a code owner November 22, 2026 20:21
@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 22, 2026 8:26pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Makes parseCurrencyInput take linear time on the crafted inputs targeted by this fix.

  • Currency parsing stays quick on long malformed cells.

Reviews (1) · Last reviewed commit: "fix(table-cells): parse currency input i..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit d97fc98 into staging Nov 22, 2026
95 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/table-cells-currency-redos branch November 23, 2026 00:04

This branch was successfully deployed

1 active deployment
Preview — de5fe80f Deployed Nov 22, 2026 by vercel[bot]
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.

1 participant