Skip to content

Commit

Permalink
when the word get last, but key word is not end, return empty
Browse files Browse the repository at this point in the history
  • Loading branch information
luolinae86 committed Jun 25, 2020
1 parent 2341675 commit f75d767
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/sensitive.rb
Expand Up @@ -52,11 +52,13 @@ def filter(word)
sensitive_word = ''
temp = words.clone
word = word.strip.gsub(%r{[^\p{Han}+/ua-zA-Z0-9]}, '')
word.chars.each do |char|
word.chars.each_with_index do |char, index|
if temp.key? char
matched_one = true
sensitive_word += char
break if temp[char][:is_end]
# 如果被检测的词已是最后一个,但关键字还不是最后,则返为空
return '' if index == word.size - 1
temp = temp[char][:value]
else
sensitive_word = ''
Expand Down

0 comments on commit f75d767

Please sign in to comment.