Skip to content

Fix missing Z-search matches when inputs contain dollar signs - #2778

Open
pralav-25 wants to merge 1 commit into
keon:mainfrom
pralav-25:fix_z_search_dollar_matches
Open

pralav-25 wants to merge 1 commit into
keon:mainfrom
pralav-25:fix_z_search_dollar_matches

Conversation

@pralav-25

@pralav-25 pralav-25 commented Sep 27, 2026 •

Copy link
Copy Markdown

z_search('$$$', '$') returns [2], losing the first two matches. A Z match may extend past the separator when $ occurs in the input; checking z[i] >= len(pattern) recognizes every valid match without changing the algorithm's complexity or empty-input behavior.

Adds literal-dollar and Unicode regressions plus an exhaustive str.startswith oracle over short strings.

Validation on Python 3.12.14:

  • The new test file reproduced 6 failing cases on unmodified main.
  • python -m pytest -q: 612 passed.
  • python -m pytest --doctest-modules algorithms/ -q: 480 passed, 1 skipped.
  • ruff check algorithms/ tests/ and git diff --check: passed.

Prepared with AI assistance; the failures and fixes above were reproduced locally.

Summary by CodeRabbit

  • Bug Fixes

    • Z-algorithm search now includes matches that extend beyond the pattern length, including when the text or pattern contains $.
  • Tests

    • Added coverage for overlapping matches, empty inputs, and searches involving $.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: d6982c88-e315-45ef-bc8c-38555c9707a2

📥 Commits

Reviewing files that changed from the base of the PR and between bd1d152 and dd37093.

📒 Files selected for processing (2)
  • algorithms/string/z_algorithm.py
  • tests/test_z_search_delimiters.py

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


📝 Walkthrough

Walkthrough

z_search now accepts matches whose Z-value is at least the pattern length. Added tests cover dollar-sign characters, overlapping matches, exhaustive short-string comparisons, and empty arguments.

Changes

Z search matching

Layer / File(s) Summary
Match detection and validation
algorithms/string/z_algorithm.py, tests/test_z_search_delimiters.py
The documentation describes Z-values that exceed the pattern length. z_search accepts those matches. Tests check dollar-sign matching, overlapping results, short strings against a startswith oracle, and empty arguments.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to dd370

The change appears ready to merge after normal checks; no actionable risk remains identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing missing Z-search matches when inputs contain dollar signs.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

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

None yet

Development

Successfully merging this pull request may close these issues.

1 participant