Repository navigation
Fix history search for a lone slash matching every item - #1858
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1858 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 23 23
Lines 6773 6773
=======================================
Hits 6757 6757
Misses 16 16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
Thanks for the PR, @mokshupadhyay, and for covering both the I reproduced this on 4.4.5. With I agree this is a bug. A lone slash cannot enclose a pattern, but 4.4.5 counts it as both delimiters and strips it away. I checked that your patch makes Could you use a built-in command such as |
Keep the test independent of the host shell and filesystem, as asked in review.
|
Thanks for reproducing it and for the review. Done in a follow-up commit: the CLI test now runs |
The
historycommand treats an argument that starts and ends with/as a regex, with the slashes as delimiters (history /foo/). A lone/both starts and ends with a slash, so it was treated as a regex with an empty pattern between the delimiters, which matches every item. Searching the history for a slash returned the whole history.Real result with three history items, only one of which contains a slash (
History.regex_search("/")), onmainand with this change:The fix requires more than one character before treating the argument as
/regex/, inHistory.regex_searchand in the call site that decides between regex, index and text search (Cmd._get_history). A lone/is now a plain text search, and/regex/behaves as before.Tests:
test_history_regex_search_single_slash_is_literalandtest_history_literal_search_for_single_slashintests/test_history.py; both fail onmainand pass now.pytest tests/test_history.py: 836 passed (with the two new ones).make check(ruff, prettier, typos, ty, mypy) passes. I did not runmake docs-test, and I did not add aCHANGELOG.mdentry becauseAGENTS.mdasks agents not to commit markdown files without asking first; let me know if you want one.