Skip to content

Commit 227e6e4

Browse files
committed
Merge pull request #997 from projectblacklight/escape-numeric-data
When serializing numeric data to fq, ensure we properly escape the data
2 parents 9207d38 + 271803c commit 227e6e4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/blacklight/request_builders.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def facet_value_to_fq_string(facet_field, value)
277277
when (value.is_a?(TrueClass) or value.is_a?(FalseClass) or value == 'true' or value == 'false'),
278278
(value.is_a?(Integer) or (value.to_i.to_s == value if value.respond_to? :to_i)),
279279
(value.is_a?(Float) or (value.to_f.to_s == value if value.respond_to? :to_f))
280-
"#{prefix}#{facet_field}:#{value}"
280+
"#{prefix}#{facet_field}:#{RSolr.escape(value.to_s)}"
281281
when value.is_a?(Range)
282282
"#{prefix}#{facet_field}:[#{value.first} TO #{value.last}]"
283283
else

spec/lib/blacklight/solr_helper_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,15 @@ def logger
252252
end
253253

254254
it "should pass floats through" do
255-
expect(subject.send(:facet_value_to_fq_string, "facet_name", 1.11)).to eq "facet_name:1.11"
255+
expect(subject.send(:facet_value_to_fq_string, "facet_name", 1.11)).to eq "facet_name:1\\.11"
256256
end
257257

258258
it "should pass floats through" do
259-
expect(subject.send(:facet_value_to_fq_string, "facet_name", "1.11")).to eq "facet_name:1.11"
259+
expect(subject.send(:facet_value_to_fq_string, "facet_name", "1.11")).to eq "facet_name:1\\.11"
260+
end
261+
262+
it "should escape negative integers" do
263+
expect(subject.send(:facet_value_to_fq_string, "facet_name", -1)).to eq "facet_name:\\-1"
260264
end
261265

262266
it "should pass date-type fields through" do

0 commit comments

Comments
 (0)