riddle 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,19 @@
1
1
  language: ruby
2
+ before_install:
3
+ - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-1.10_i386_12.04.deb
4
+ - sudo dpkg -i fs-sphinx-1.10_i386_12.04.deb
5
+ - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.0.4_i386_12.04.deb
6
+ - sudo dpkg -i fs-sphinx-2.0.4_i386_12.04.deb
7
+ - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.0.6_i386_12.04.deb
8
+ - sudo dpkg -i fs-sphinx-2.0.6_i386_12.04.deb
2
9
  rvm:
3
10
  - 1.8.7
4
11
  - 1.9.2
5
12
  - 1.9.3
6
- - ree
7
13
  - jruby-18mode
8
- - ruby-head
9
14
  env:
10
- - SPHINX_BIN=/usr/local/sphinx-0.9.9/bin SPHINX_VERSION=0.9.9
11
15
  - SPHINX_BIN=/usr/local/sphinx-1.10/bin SPHINX_VERSION=1.10
12
- - SPHINX_BIN=/usr/local/sphinx-2.0.1/bin SPHINX_VERSION=2.0.1
16
+ - SPHINX_BIN=/usr/local/sphinx-2.0.4/bin SPHINX_VERSION=2.0.4
17
+ - SPHINX_BIN=/usr/local/sphinx-2.0.6/bin SPHINX_VERSION=2.0.6
13
18
  before_script: killall searchd; echo ''
14
19
  after_script: killall searchd; echo ''
data/Gemfile CHANGED
@@ -2,5 +2,5 @@ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'mysql2', '0.3.2', :platform => :ruby
6
- gem 'jdbc-mysql', '>= 5.1.13', :platform => :jruby
5
+ gem 'mysql2', '0.3.2', :platform => :ruby
6
+ gem 'jdbc-mysql', '5.1.13', :platform => :jruby
data/HISTORY CHANGED
@@ -1,3 +1,12 @@
1
+ 1.5.5 - February 23rd 2013
2
+ - Added Riddle::Query.escape for SphinxQL queries.
3
+ - Fixed failover handling (Ngan Pham).
4
+ - Improved encoding default check (Darcy Brown).
5
+ - Removing REE support (as it is no longer supported either).
6
+ - Client key is used for binary protocol persistent connections (if set).
7
+ - Escaping single quotes in SphinxQL snippets calls.
8
+ - Regex fix for matching {'s (Rob Golkosky).
9
+
1
10
  1.5.4 - January 2nd 2013
2
11
  - RT indices get most of the same settings as SQL indices.
3
12
  - Escape single quotes in SphinxQL match queries, given we're wrapping them in single quotes.
@@ -89,3 +89,5 @@ Thanks to the following people who have contributed to Riddle in some shape or f
89
89
  * Ilia Lobsanov
90
90
  * Aleksey Morozov
91
91
  * S. Christoffer Eliesen
92
+ * Rob Golkosky
93
+ * Darcy Brown
@@ -12,7 +12,7 @@ module Riddle #:nodoc:
12
12
  #
13
13
  end
14
14
 
15
- def self.encode(data, encoding = defined?(::Encoding) && ::Encoding.default_external)
15
+ def self.encode(data, encoding = @@use_encoding && ::Encoding.default_external)
16
16
  if @@use_encoding
17
17
  data.force_encoding(encoding)
18
18
  else
@@ -4,8 +4,8 @@ Riddle::Client::Versions[:update] = 0x102
4
4
  class Riddle::Client
5
5
  private
6
6
 
7
- def initialise_connection
8
- socket = initialise_socket
7
+ def initialise_connection(available_server)
8
+ socket = initialise_socket(available_server)
9
9
 
10
10
  # Send version
11
11
  socket.send [1].pack('N'), 0
@@ -481,9 +481,7 @@ module Riddle
481
481
 
482
482
  return if Versions[:search] < 0x116
483
483
 
484
- @socket.send [
485
- Commands[:persist], 0, 4, 1
486
- ].pack("nnNN"), 0
484
+ @socket.send request_header(:persist) + [1].pack('N'), 0
487
485
  end
488
486
 
489
487
  def close
@@ -498,10 +496,10 @@ module Riddle
498
496
  available_servers = servers.dup
499
497
 
500
498
  if @timeout == 0
501
- @socket = initialise_connection
499
+ @socket = initialise_connection(available_servers.first)
502
500
  else
503
501
  begin
504
- Timeout.timeout(@timeout) { @socket = initialise_connection }
502
+ Timeout.timeout(@timeout) { @socket = initialise_connection(available_servers.first) }
505
503
  rescue Timeout::Error, Riddle::ConnectionError => e
506
504
  failed_servers ||= []
507
505
  failed_servers << available_servers.shift
@@ -546,8 +544,8 @@ module Riddle
546
544
  end
547
545
  end
548
546
 
549
- def initialise_connection
550
- socket = initialise_socket
547
+ def initialise_connection(available_server)
548
+ socket = initialise_socket(available_server)
551
549
 
552
550
  # Checking version
553
551
  version = socket.recv(4).unpack('N*').first
@@ -562,24 +560,24 @@ module Riddle
562
560
  socket
563
561
  end
564
562
 
565
- def initialise_socket
563
+ def initialise_socket(available_server)
566
564
  tries = 0
567
565
  begin
568
566
  socket = if self.connection
569
567
  self.connection.call(self)
570
568
  elsif self.class.connection
571
569
  self.class.connection.call(self)
572
- elsif server && server.index('/') == 0
573
- UNIXSocket.new server
574
- elsif server
575
- TCPSocket.new server, @port
570
+ elsif available_server && available_server.index('/') == 0
571
+ UNIXSocket.new available_server
572
+ elsif available_server
573
+ TCPSocket.new available_server, @port
576
574
  else
577
575
  raise "Server not set."
578
576
  end
579
577
  rescue Errno::ETIMEDOUT, Errno::ECONNRESET, Errno::ECONNREFUSED => e
580
578
  retry if (tries += 1) < 5
581
579
  raise Riddle::ConnectionError,
582
- "Connection to #{server} on #{@port} failed. #{e.message}"
580
+ "Connection to #{available_server} on #{@port} failed. #{e.message}"
583
581
  end
584
582
 
585
583
  socket
@@ -598,6 +596,8 @@ module Riddle
598
596
  end
599
597
  when :status
600
598
  [Commands[command], Versions[command], 4, 1].pack("nnNN")
599
+ when :persist
600
+ [Commands[command], 0, 4 + length].pack("nnN")
601
601
  else
602
602
  [Commands[command], Versions[command], length].pack("nnN")
603
603
  end
@@ -59,7 +59,7 @@ class Riddle::Configuration::Parser
59
59
 
60
60
  def each_with_prefix(prefix)
61
61
  inner.keys.select { |key| key[/^#{prefix}\s+/] }.each do |key|
62
- yield key.gsub(/^#{prefix}\s+/, '').gsub(/\s*{$/, ''), inner[key]
62
+ yield key.gsub(/^#{prefix}\s+/, '').gsub(/\s*\{$/, ''), inner[key]
63
63
  end
64
64
  end
65
65
 
@@ -36,9 +36,9 @@ module Riddle
36
36
  if options[:nodetach]
37
37
  exec(cmd)
38
38
  elsif RUBY_PLATFORM =~ /mswin|mingw/
39
- system("start /B #{cmd} 1> NUL 2>&1")
39
+ output = system("start /B #{cmd} 1> NUL 2>&1")
40
40
  else
41
- `#{cmd}`
41
+ output = `#{cmd}`
42
42
  end
43
43
 
44
44
  sleep(1)
@@ -46,6 +46,8 @@ module Riddle
46
46
  unless running?
47
47
  puts "Failed to start searchd daemon. Check #{@configuration.searchd.log}."
48
48
  end
49
+
50
+ output
49
51
  end
50
52
 
51
53
  def stop
@@ -58,6 +58,9 @@ module Riddle::Query
58
58
  end
59
59
 
60
60
  def self.snippets(data, index, query, options = nil)
61
+ data.gsub!("'") { |x| "\\'" }
62
+ query.gsub!("'") { |x| "\\'" }
63
+
61
64
  options = ', ' + options.keys.collect { |key|
62
65
  value = options[key]
63
66
  value = "'#{value}'" if value.is_a?(String)
@@ -95,6 +98,14 @@ module Riddle::Query
95
98
  value
96
99
  end
97
100
  end
101
+
102
+ def self.escape(string)
103
+ string.gsub("\\") { |match|
104
+ "\\\\"
105
+ }.gsub(/[\(\)\|\-!@~"\/\^\$]/) { |match|
106
+ "\\\\#{match}"
107
+ }
108
+ end
98
109
  end
99
110
 
100
111
  require 'riddle/query/delete'
@@ -1,3 +1,3 @@
1
1
  module Riddle
2
- Version = '1.5.4'
2
+ Version = '1.5.5'
3
3
  end
@@ -46,6 +46,16 @@ describe Riddle::Query do
46
46
  Riddle::Query.snippets('foo bar baz', 'foo_core', 'foo',
47
47
  :before_match => '<strong>').should == "CALL SNIPPETS('foo bar baz', 'foo_core', 'foo', '<strong>' AS before_match)"
48
48
  end
49
+
50
+ it "escapes quotes in the text data" do
51
+ Riddle::Query.snippets("foo bar 'baz", 'foo_core', 'foo').
52
+ should == "CALL SNIPPETS('foo bar \\'baz', 'foo_core', 'foo')"
53
+ end
54
+
55
+ it "escapes quotes in the query data" do
56
+ Riddle::Query.snippets("foo bar baz", 'foo_core', "foo'").
57
+ should == "CALL SNIPPETS('foo bar baz', 'foo_core', 'foo\\'')"
58
+ end
49
59
  end
50
60
 
51
61
  describe '.create_function' do
@@ -61,4 +71,16 @@ describe Riddle::Query do
61
71
  should == 'UPDATE foo_core SET deleted = 1 WHERE id = 5'
62
72
  end
63
73
  end
74
+
75
+ describe '.escape' do
76
+ %w(( ) | - ! @ ~ " / ^ $).each do |reserved|
77
+ it "escapes #{reserved}" do
78
+ Riddle::Query.escape(reserved).should == "\\\\#{reserved}"
79
+ end
80
+ end
81
+
82
+ it "escapes \\" do
83
+ Riddle::Query.escape("\\").should == "\\\\"
84
+ end
85
+ end
64
86
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riddle
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 4
10
- version: 1.5.4
9
+ - 5
10
+ version: 1.5.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pat Allan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-01-02 00:00:00 +11:00
18
+ date: 2013-02-23 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency