-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# encoding: UTF-8 | ||
|
||
RSpec.describe Solr::Support::StringExtensions do | ||
using Solr::Support::StringExtensions | ||
|
||
describe '.solr_escape' do | ||
it "adds backslash to Solr query syntax chars" do | ||
# per http://lucene.apache.org/core/4_0_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#Escaping_Special_Characters | ||
special_chars = [ "+", "-", "&", "|", "!", "(", ")", "{", "}", "[", "]", "^", '"', "~", "*", "?", ":", "\\", "/" ] | ||
escaped_str = "aa#{special_chars.join('aa')}aa".solr_escape | ||
special_chars.each { |c| | ||
# note that the ruby code sending the query to Solr will un-escape the backslashes | ||
# so the result sent to Solr is ultimately a single backslash in front of the particular character | ||
expect(escaped_str).to match "\\#{c}" | ||
} | ||
end | ||
|
||
it "leaves other chars alone" do | ||
str = "nothing to see here; let's move along people." | ||
expect(str.solr_escape).to eq str | ||
end | ||
end | ||
end |