aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Dunn2015-04-17 12:07:45 -0700
committerMike McQuaid2015-04-21 10:54:29 +0100
commit07f3aaf658601b781a438dba786029872e99556f (patch)
treebe18afeefbadea52ec436ab19f795ded7f03db7c
parent15e89e3fe8d76786869c348b3f210aa4dd6ae8f0 (diff)
downloadhomebrew-07f3aaf658601b781a438dba786029872e99556f.tar.bz2
cmd/search: notification on attempted regex searches
Closes #38760. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
-rw-r--r--Library/Homebrew/cmd/search.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index d5a826eda..98031fe7b 100644
--- a/Library/Homebrew/cmd/search.rb
+++ b/Library/Homebrew/cmd/search.rb
@@ -61,7 +61,16 @@ module Homebrew
end
end
end
-
+ metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ? .]
+ bad_regex = metacharacters.any? do |char|
+ ARGV.any? do |arg|
+ arg.include?(char) && !arg.start_with?('/')
+ end
+ end
+ if ARGV.any? && bad_regex
+ ohai "Did you mean to perform a regular expression search?"
+ ohai "Surround your query with /slashes/ to search by regex."
+ end
raise SEARCH_ERROR_QUEUE.pop unless SEARCH_ERROR_QUEUE.empty?
end