Skip to content

fix(toml): strip separators in linear time, shorten the error - #1923

Open
quietbits wants to merge 2 commits into
mainfrom
issue-1909
Open

quietbits wants to merge 2 commits into
mainfrom
issue-1909

Conversation

@quietbits

Copy link
Copy Markdown
Contributor
  • Fixed StellarToml.Resolver.resolve() taking quadratic time on a long run of / or \ that is not at the end of the domain — 100,000 slashes followed by x blocked the event loop for about 4 s before the call rejected; it now takes under 1 ms
  • Kept the result the same for every input, so domains with a trailing separator still resolve as fix(toml): keep a malformed domain from redirecting the request #1720 decided; a test compares the new strip with the old regex on every string up to 6 characters
  • Replaced the regex with a backward loop rather than a lookbehind regex, because a reader can see the loop is linear without knowing how the regex engine backtracks
  • Limited the domain in the Invalid domain error to its first 256 characters — before, a hostile input made an error message of any size in logs; the domain checks still use the full input, and every real host name (253 characters at most) still shows in full
  • Updated the domain parameter doc to say that trailing backslashes are also ignored, which the code already did

Closes #1909

@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Nov 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues require resolution for the resolver performance and error-output changes.

No open issues 🎉

What changed in this PR

This PR addresses #1909 by removing quadratic-time separator stripping from the Stellar TOML resolver while preserving the domain normalization behavior established in #1720.

Changes:

  • Replaces the trailing-separator regex with a linear-time backward loop.
  • Limits domain text in validation errors to the first 256 characters.
  • Adds regression tests and updates documentation and release notes.
File Description
test/​unit/​stellar_toml_resolver.test.ts Adds timing, error truncation, and separator-stripping equivalence tests.
src/​stellartoml/​utils.ts Adds the linear-time trailing-separator helper.
src/​stellartoml/​index.ts Uses the helper, truncates error output, and clarifies parameter documentation.
docs/​reference/​seps-toml.md Updates separator documentation and source links.
CHANGELOG.md Records the performance fix and bounded error output.

Review effort: Balanced

@quietbits
quietbits requested a review from Ryang-21 November 24, 2026 20:13

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog (Not Ready)

Development

Successfully merging this pull request may close these issues.

StellarToml.Resolver.resolve takes quadratic time on a long run of slashes

3 participants