Permalink
Browse files

Let catch() generate a random tag on Ruby 1.9.

  • Loading branch information...
knu committed Aug 15, 2011
1 parent 1be1472 commit 24649c26f13934b6bad70a00249f434d6a49270d
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/nokogiri/html/document.rb
@@ -135,8 +135,13 @@ def initialize(encoding)
class EncodingReader # :nodoc:
class SAXHandler < Nokogiri::XML::SAX::Document # :nodoc:
+ def initialize(jumptag)
+ @jumptag = jumptag
+ super()
+ end
+
def found(encoding)
- throw :found, encoding
+ throw @jumptag, encoding
end
def not_found(encoding)
@@ -169,9 +174,8 @@ def self.detect_encoding(chunk)
return m[4]
end
- parser = Nokogiri::HTML::SAX::Parser.new(SAXHandler.new)
- catch(:found) {
- parser.parse(chunk)
+ catch(*if RUBY_VERSION < '1.9' then :encoding_found end) { |tag|
+ Nokogiri::HTML::SAX::Parser.new(SAXHandler.new(tag)).parse(chunk)
nil
}
rescue

0 comments on commit 24649c2

Please sign in to comment.