Skip to content

Commit

Permalink
Fixing the RegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosba committed Nov 14, 2024
1 parent 0c500f1 commit 79e8413
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/check_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ def initialize(options, file = nil, team_id = Team.current&.id)

def adjust_keyword_filter
unless @options['keyword'].blank?
# This regex removes all characters except letters, numbers, hashtag and whitespace in any language - stripping out special characters can improve match results
@options['keyword'].gsub!(/[^[:word:]\s#]/, ' ')
# This regex removes all characters except letters, numbers, hashtag, search operators, emojis and whitespace
# in any language - stripping out special characters can improve match results
@options['keyword'].gsub!(/[^[:word:]\s#~+-|()"\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1F1E6}-\u{1F1FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/, ' ')

Check warning

Code scanning / CodeQL

Overly permissive regular expression range Medium

Suspicious character range that is equivalent to \[+,\\-.\\/0-9:;<=>?@A-Z\\\[\\\\\\\]^_`a-z{{|\].

# Set fuzzy matching for keyword search, right now with automatic Levenshtein Edit Distance
# https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html
# https://github.com/elastic/elasticsearch/issues/23366
@options['keyword'] = "#{@options['keyword']}~" if !@options['keyword'].blank? && @options['fuzzy']
@options['keyword'] = "#{@options['keyword']}~" if @options['fuzzy']
end
end

Expand Down

0 comments on commit 79e8413

Please sign in to comment.