Skip to content

Commit

Permalink
Escaping the autocomplete queries to fix hotsh#666
Browse files Browse the repository at this point in the history
  • Loading branch information
egrajeda committed Oct 2, 2012
1 parent 000d354 commit bbaa691
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def autocomplete(query)
return []
end

query = '^' + query.downcase + '.*'
query = '^' + Regexp.escape(query) + '.*'
following.inject([]) do |result, obj|
if /#{query}/i =~ obj.author.fully_qualified_name
result << { :label => obj.author.fully_qualified_name.downcase }
Expand Down
5 changes: 5 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ def stub_superfeedr_request_for_user(user)
@result = @bob.autocomplete('ta')
assert_equal [], @result
end

it "escapes special characters" do
@result = @bob.autocomplete('r+(')
assert_equal [], @result
end
end

describe "self#find_by_case_insensitive_username" do
Expand Down

0 comments on commit bbaa691

Please sign in to comment.