Repository navigation
fix(table-cells): parse currency input in linear time - #10316
Merged
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryMakes
Reviews (1) · Last reviewed commit: "fix(table-cells): parse currency input i..." · Reviewed by Greptile |
This branch was successfully deployed
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.
Summary
parseCurrencyInputbacktracked quadratically on crafted cells (CodeQLjs/polynomial-redos); table imports and coercion run it per cell on the server, so one long cell could stall the event loop for secondsCURRENCY_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 returnssign ?? ''CURRENCY_MARKER_SUFFIX: unanchored with a leading whitespace run, soreplacerescanned the run from every start → drop the whitespace runs and match againsttrimEnd(); the whitespace left before the marker is stripped with every other space right afterAMOUNT_SHAPE: overlapping[\d.,]*\d[\d.,]*→[.,]*\d[\d.,]*(same language, disjoint runs)[\s ]→\s(\sandtrimEndalready cover U+00A0/U+202F); no length cap, no behaviour changepackages/table-cells/srcchecked and measured: all linear (ttl.ts's/0+$/runs on at most 6 chars)Type of Change
Testing
Intloutput 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)expectLinearGrowthcases incurrency.test.tsfail 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 1mstable-cells,workspace-codekinds, andapps/simtable import/coercion/column-type tests; lint, type-check,check:audits,check:test-types, block-registry check, rootbun run test(one unrelatedworkflow-codescaling flake at 20.5, green on rerun)Checklist
test-auditauthoring gate)