Skip to content

Commit

Permalink
properly escaping regex terms
Browse files Browse the repository at this point in the history
  • Loading branch information
tansengming committed Mar 3, 2011
1 parent c52efa7 commit 1999955
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions lib/term-extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def extract(content)
if @collapse_terms
terms.each_key do |term1|
terms.each_key do |term2|
terms.delete(term2) if term1.length > term2.length && (term1 =~ /[^A-Za-z0-9]#{clean_regex(term2)}$/ || term1 =~ /^#{clean_regex(term2)}[^A-Za-z0-9]/)
terms.delete(term2) if term1.length > term2.length && (term1 =~ /[^A-Za-z0-9]#{Regexp.escape(term2)}$/ || term1 =~ /^#{Regexp.escape(term2)}[^A-Za-z0-9]/)
end
end
end
Expand All @@ -120,10 +120,6 @@ def extract(content)
end

protected
def clean_regex(term)
term.gsub(/([\*\+\.\?])/, '\\\\\1')
end

def preprocess_tags(pos)
# Add in full stops to tag list to allow multiterms to work
tags = []
Expand Down

0 comments on commit 1999955

Please sign in to comment.