Skip to content

Fixed opportunity search error on unescaped regex special characters **#525** #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/opportunities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ def geocode_location(location)
def get_jobs_for(chosen_location, tag, page, query = nil, remote_allowed = false)
scope = Opportunity

escaped_query = query.nil? ? query : Regexp.escape(query)

if remote_allowed
scope = scope.where(remote: true)
else
scope = scope.by_city(chosen_location) if chosen_location && chosen_location.length > 0
end

scope = scope.by_tag(tag) unless tag.nil?
scope = scope.by_query(query) if query
scope = scope.by_query(escaped_query) if escaped_query
# TODO: Verify that there are no unmigrated teams
scope = scope.where('team_id is not null')
scope.offset((page-1) * 20)
Expand Down
11 changes: 11 additions & 0 deletions spec/controllers/opportunity_controlller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@
expect(assigns(:jobs)).to_not be_include(@opportunity2)
end
end

context "by query with keywords containing regexp special characters" do
it "should NOT fail when querying with keywords containing '+'" do
get :index, location: nil, q: 'C++'
expect(assigns(:jobs))
end
it "should NOT fail when querying with keywords containing '.^$*+?()[{\|'" do
get :index, location: nil, q: 'java .^$*+?()[{\|'
expect(assigns(:jobs))
end
end
end
end
end