allow @ and + characters for search

This commit is contained in:
Daeho Ro 2024-09-17 12:20:17 +09:00
parent 42c11a4ded
commit 47e70ab3ea
2 changed files with 7 additions and 2 deletions

View File

@ -150,7 +150,7 @@ module Homebrew
end end
def self.simplify_string(string) def self.simplify_string(string)
string.downcase.gsub(/[^a-z\d]/i, "") string.downcase.gsub(/[^a-z\d@+]/i, "")
end end
def self.search_regex(selectable, regex) def self.search_regex(selectable, regex)

View File

@ -20,7 +20,7 @@ RSpec.describe Homebrew::Search do
end end
describe "#search" do describe "#search" do
let(:collection) { ["with-dashes"] } let(:collection) { ["with-dashes", "with@alpha", "with+plus"] }
context "when given a block" do context "when given a block" do
let(:collection) { [["with-dashes", "withdashes"]] } let(:collection) { [["with-dashes", "withdashes"]] }
@ -41,6 +41,11 @@ RSpec.describe Homebrew::Search do
it "simplifies both the query and searched strings" do it "simplifies both the query and searched strings" do
expect(described_class.search(collection, "with dashes")).to eq ["with-dashes"] expect(described_class.search(collection, "with dashes")).to eq ["with-dashes"]
end end
it "does not simplify strings with @ and + characters" do
expect(described_class.search(collection, "with@alpha")).to eq ["with@alpha"]
expect(described_class.search(collection, "with+plus")).to eq ["with+plus"]
end
end end
context "when searching a Hash" do context "when searching a Hash" do