commit 6f1d5f202288ebb71fecb90d4f241b2d3b2d54cb
parent 27e1c05fcb6cb1ae654a524be37fe6849f547980
Author: Gaute Hope <eg@gaute.vetsj.com>
Date: Sat, 28 Sep 2013 13:38:14 +0200
Merge #138: Fix crash when searching by date
It seems Xapian returns query descriptions containing non-UTF8 characters
(binary?) when creating queries for dates. This patch uses a default string
when logging the generated query.
Fixes #138
Squashed commit of the following:
commit e5516bd4c0f173848e5455df50208a31c23d35e8
Author: Eric Weikl
Date: Sun Sep 8 13:05:35 2013 +0200
fix copy&paste
commit 3293a251cad53586bb4d71af0b20e751b8b6e36e
Author: Eric Weikl
Date: Sun Sep 1 17:03:41 2013 +0200
Fix crash when searching by date
It seems Xapian returns query descriptions containing non-UTF8 characters
(binary?) when creating queries for dates. This patch uses a default string
when logging the generated query.
Fixes #138
Diffstat:
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -492,7 +492,7 @@ EOS
raise ParseError, "xapian query parser error: #{e}"
end
- debug "parsed xapian query: #{Util::Query.describe(xapian_query)}"
+ debug "parsed xapian query: #{Util::Query.describe(xapian_query, subs)}"
raise ParseError if xapian_query.nil? or xapian_query.empty?
query[:qobj] = xapian_query
diff --git a/lib/sup/util/query.rb b/lib/sup/util/query.rb
@@ -3,10 +3,13 @@ module Redwood
module Query
class QueryDescriptionError < ArgumentError; end
- def self.describe query
+ def self.describe(query, fallback = nil)
d = query.description.force_encoding("UTF-8")
- raise QueryDescriptionError.new(d) unless d.valid_encoding?
+ unless d.valid_encoding?
+ raise QueryDescriptionError.new(d) unless fallback
+ d = fallback
+ end
return d
end
end
diff --git a/test/unit/util/test_query.rb b/test/unit/util/test_query.rb
@@ -33,5 +33,14 @@ describe Redwood::Util::Query do
_ = life + query.description
end
end
+
+ it "returns a valid UTF-8 fallback description of bad input" do
+ msg = "asdfa \xc3\x28 åasdf"
+ query = Xapian::Query.new msg
+
+ desc = Redwood::Util::Query.describe(query, "invalid query")
+
+ assert_equal("invalid query", desc)
+ end
end
end