Skip to content

functions: match TEXTSPLIT/TEXTBEFORE/TEXTAFTER delimiters through an index, within a work limit - #3263

Merged
dylanmtaylor merged 3 commits into
mainfrom
fix/sec-text-delimiter-matching
Nov 4, 2026
Merged

dylanmtaylor merged 3 commits into
mainfrom
fix/sec-text-delimiter-matching

Conversation

@dylanmtaylor

@dylanmtaylor dylanmtaylor commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What was wrong

find_matches in crates/functions/src/text.rs (used by TEXTSPLIT, TEXTBEFORE and TEXTAFTER) tried every delimiter at every text position, including repeated delimiters. A formula can pass an array of thousands of delimiters, so the work was text length × delimiter count × delimiter length while the result stayed small.

What changed

  • Delimiters are sorted and deduplicated, then grouped by their first character (last character when searching from the end). At each position only the group for the character there is compared.
  • The characters compared in one search are counted; past MAX_MATCH_WORK (100 million) the function returns #VALUE!. find_matches and split_by now return R<…> and their callers propagate it.
  • Matching rules are unchanged: longest delimiter wins, non-overlapping, case folding as before.

Blast radius

TEXTSPLIT, TEXTBEFORE, TEXTAFTER. Results are the same except that searches over the work limit return #VALUE! instead of running on.

Checks run

  • cargo test -p gridcraft-functions (new delimiter_matching_stays_bounded: 50,000 copies of one delimiter, 5,000 distinct 1,000-character delimiters over 30,000 characters, longest-match checks from both ends)
  • cargo clippy -p gridcraft-functions --all-targets -- -D warnings
  • cargo fmt --check

Checks not run

  • full workspace tests, wasm build

Summary by CodeRabbit

  • Bug Fixes
    • TEXTBEFORE, TEXTAFTER, and TEXTSPLIT handle repeated delimiters consistently while preserving longest-match behavior and scan direction.
    • Delimiter matching that exceeds the supported work limit now returns #VALUE!, and the error is propagated consistently by these functions.
    • Empty-delimiter behavior remains unchanged.

… index, within a work limit

The delimiter matcher compared every delimiter, duplicates included, at
every position of the text. Delimiters are now deduplicated and grouped
by the character a match is anchored on, and a search that would
compare more than 100 million characters returns #VALUE!.
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 8b65dcd and cead2f8.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Delimiter matching now indexes deduplicated delimiters by their scan-direction anchor and limits comparison work. TEXTBEFORE, TEXTAFTER, and TEXTSPLIT propagate matching errors.

Changes: Delimiter matching

Layer / File(s) Summary
Indexed delimiter matching
crates/functions/src/text.rs
find_matches indexes nonempty delimiters by their first or last character, selects the longest match, and returns #VALUE! when comparison work exceeds 100,000,000.
Error propagation and coverage
crates/functions/src/text.rs
text_before_after, split_by, and textsplit propagate matching errors. Tests cover repeated delimiters, over-budget searches, and longest-match behavior in both directions.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: echelon, silvertree2010

Merge Risk: Minimal · previous review 8b65d

Delimiter matching for TEXTBEFORE, TEXTAFTER and TEXTSPLIT now stops oversized searches with #VALUE! and otherwise behaves as before. The cap is applied per row in TEXTSPLIT rather than across the whole operation, which is a minor gap in the limit and not a correctness problem. No merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the TEXTSPLIT, TEXTBEFORE, and TEXTAFTER delimiter matching change, which is the main change in crates/functions/src/text.rs. It also names the two core ideas: matching through an inde…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the TEXTSPLIT, TEXTBEFORE, and TEXTAFTER delimiter matching change, which is the main change in crates/functions/src/text.rs. It also names the two core ideas: matching through an index and a work limit (MAX_MATCH_WORK, returning #VALUE!). It is specific and descriptive, and it is 96 characters long.

Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between e6ff2da and 8b65dcd.

Files selected for processing: 1
  • crates/functions/src/text.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@dylanmtaylor

Copy link
Copy Markdown
Member Author

Follow-up commit: the first push's new test passed integer literals where the test helper takes f64, so the test target did not compile (my local run had reused a stale build). Fixed; cargo test -p gridcraft-functions (157 passed) and clippy now pass from a clean target directory.

@dylanmtaylor

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Rate Limit Exceeded

@dylanmtaylor have exceeded the limit for the number of chat messages per hour. Please wait 25 minutes and 2 seconds before sending another message.

@dylanmtaylor

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Rate Limit Exceeded

@dylanmtaylor have exceeded the limit for the number of chat messages per hour. Please wait 25 minutes and 44 seconds before sending another message.

@dylanmtaylor
dylanmtaylor merged commit 017c805 into main Nov 4, 2026
8 of 9 checks passed
@dylanmtaylor
dylanmtaylor deleted the fix/sec-text-delimiter-matching branch November 4, 2026 03:53
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