Skip to content

Commit d39e3f8

Browse files
author
LOU Xun
committed
Add another check for non-English queries
1 parent 9a297fe commit d39e3f8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/halosir/rules.ex

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule HaloSir.Rules do
77
Don't cache sentences.
88
"""
99
def should_cache_word?(word) do
10-
not_too_long?(word) && not_sentence?(word)
10+
not_too_long?(word) && not_sentence?(word) && has_english_letter?(word)
1111
end
1212

1313
defp not_sentence?(word) do
@@ -20,4 +20,9 @@ defmodule HaloSir.Rules do
2020
defp not_too_long?(word) do
2121
String.length(word) <= 20
2222
end
23+
24+
@reg ~r/[a-zA-Z]/
25+
defp has_english_letter?(word) do
26+
Regex.match?(@reg, word)
27+
end
2328
end

test/halosir/rules_test.exs

+6
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ defmodule HaloSir.RulesTest do
2525

2626
refute should_cache_word?(sentence)
2727
end
28+
29+
test "Should not cache words with no English letter" do
30+
word = "『氷菓』"
31+
32+
refute should_cache_word?(word)
33+
end
2834
end

0 commit comments

Comments
 (0)