From 6bc8d75ab4c60a29b39883b8b384b019af6f5b2d Mon Sep 17 00:00:00 2001 From: Bounty Hunter Bot Date: Mon, 19 Jan 2026 21:42:55 +0400 Subject: [PATCH] fix: reject empty search queries --- src/cli/commands.rs | 6 ++++++ tests/integration_tests.rs | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/cli/commands.rs b/src/cli/commands.rs index f128499..5aae3b0 100644 --- a/src/cli/commands.rs +++ b/src/cli/commands.rs @@ -548,6 +548,12 @@ fn run_search_smart( interactive: bool, sync: bool, ) -> Result<()> { + let query = query.trim(); + if query.is_empty() { + ui::print_error("Search query cannot be empty"); + return Ok(()); + } + if sync { run_index( config, diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index efb71d9..8e5dc56 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -59,3 +59,23 @@ fn test_config_show() { .success() .stdout(predicate::str::contains("Chunk size")); } + +#[test] +fn test_search_empty_query_should_fail() { + vgrep() + .arg("search") + .arg("") + .assert() + .failure() + .stderr(predicate::str::contains("Search query cannot be empty")); +} + +#[test] +fn test_search_whitespace_query_should_fail() { + vgrep() + .arg("search") + .arg(" ") + .assert() + .failure() + .stderr(predicate::str::contains("Search query cannot be empty")); +}