From 4ac93502ed83444395f86d28ade1ea3f45886002 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 21 Jun 2021 14:33:06 -0400 Subject: [PATCH] deprecated: Nokogiri::HTML5.get --- CHANGELOG.md | 5 +++++ lib/nokogiri/html5.rb | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 841df96ae4..e1426763ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,11 @@ Future releases of Nokogiri may deprecate `HTML` methods or otherwise change thi * [CRuby] Speed up (slightly) the compile time of packaged libraries `libiconv`, `libxml2`, and `libxslt` by using autoconf's `--disable-dependency-tracking` option. ("ruby" platform gem only.) +### Deprecated + +* Deprecating Nokogumbo's `Nokogiri::HTML5.get`. This method will be removed in a future version of Nokogiri. + + ### Dependencies * [CRuby] Upgrade mini_portile2 dependency from `~> 2.5.0` to `~> 2.6.1`. ("ruby" platform gem only.) diff --git a/lib/nokogiri/html5.rb b/lib/nokogiri/html5.rb index f7105ac55d..c76b4a6d4c 100644 --- a/lib/nokogiri/html5.rb +++ b/lib/nokogiri/html5.rb @@ -250,6 +250,14 @@ def self.fragment(string, encoding = nil, **options) # * :follow_limit => number of redirects which are followed # * :basic_auth => [username, password] def self.get(uri, options={}) + warn("Nokogiri::HTML5.get is deprecated and will be removed in a future version of Nokogiri.", + uplevel: 1, category: :deprecated) + get_impl(uri, options) + end + + private + + def self.get_impl(uri, options={}) headers = options.clone headers = {:follow_limit => headers} if Numeric === headers # deprecated limit=headers[:follow_limit] ? headers.delete(:follow_limit).to_i : 10 @@ -292,14 +300,12 @@ def self.get(uri, options={}) when Net::HTTPRedirection response.value if limit <= 1 location = URI.join(uri, response['location']) - get(location, options.merge(:follow_limit => limit-1)) + get_impl(location, options.merge(:follow_limit => limit-1)) else response.value end end - private - def self.read_and_encode(string, encoding) # Read the string with the given encoding. if string.respond_to?(:read)