- Backport Ruby 1.8.7 Regexp.union([array]) so Rack 1.2.1 works in Ruby

<= 1.8.6. This should fix issue
  http://code.google.com/p/logstash/issues/detail?id=5

  Tested in rvm with:
  'rvm 1.8.6 exec bin/logstash-web'
This commit is contained in:
Jordan Sissel 2011-01-18 14:43:40 +08:00 committed by Alexandre Dulaunoy
parent fb6e0d590d
commit 6e0684bf84
2 changed files with 29 additions and 0 deletions

View file

@ -8,3 +8,5 @@ if !String.instance_methods.include?("start_with?")
end
end
end
require "logstash/rubyfixes/regexp_union_takes_array"

View file

@ -0,0 +1,27 @@
# Check if Regexp.union takes an array. If not, monkeypatch it.
# This feature was added in Ruby 1.8.7 and is required by
# Rack 1.2.1, breaking ruby <= 1.8.6
needs_fix = false
begin
Regexp.union(["a", "b"])
rescue TypeError => e
if e.message == "can't convert Array into String"
needs_fix = true
end
end
if needs_fix
class Regexp
class << self
alias_method :orig_regexp_union, :union
public
def union(*args)
if args[0].is_a?(Array) && args.size == 1
return orig_regexp_union(*args[0])
end
return orig_regexp_union(*args)
end # def union
end # class << self
end # class Regexp
end # if needs_fix