Skip to content

Commit

Permalink
remove deprecations in preparation for v1.16 (#3041)
Browse files Browse the repository at this point in the history
**What problem is this PR intended to solve?**

Before a minor release, I generally review deprecations and look for
things we can remove.

* Removed `Nokogiri::HTML5.get` which was deprecated in v1.12.0. [#2278]
(@flavorjones)
* Removed the CSS-to-XPath utility modules
`XPathVisitorAlwaysUseBuiltins` and `XPathVisitorOptimallyUseBuiltins`,
which were deprecated in v1.13.0 in favor of `XPathVisitor` constructor
args. [#2403] (@flavorjones)
* Removed `XML::Reader#attribute_nodes` which was deprecated in v1.13.8
in favor of `#attribute_hash`. [#2598, #2599] (@flavorjones)

Also we're now specifying version numbers in remaining deprecation
warnings.

**Have you included adequate test coverage?**

Tests have been removed, otherwise no new coverage needed.

**Does this change affect the behavior of either the C or the Java
implementations?**

As documented above.
  • Loading branch information
flavorjones authored Nov 28, 2023
2 parents 5af69a3 + 819b41e commit def3710
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 256 deletions.
15 changes: 4 additions & 11 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 50`
# on 2023-06-26 20:38:41 UTC using RuboCop version 1.53.1.
# on 2023-11-28 13:36:03 UTC using RuboCop version 1.57.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Lint/MixedCaseRange:
Exclude:
- 'test/test_compaction.rb'

# Offense count: 22
# Offense count: 20
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: def_self, self_class
Style/ClassMethodsDefinitions:
Exclude:
- 'lib/nokogiri/css/xpath_visitor.rb'
- 'lib/nokogiri/html4/document_fragment.rb'
- 'lib/nokogiri/html4/encoding_reader.rb'
- 'lib/nokogiri/html4/sax/parser_context.rb'
Expand All @@ -41,9 +34,9 @@ Style/MissingRespondToMissing:
Exclude:
- 'lib/nokogiri/xml/builder.rb'

# Offense count: 70
# Offense count: 68
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 250
Max: 257
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Documentation on what can be matched:
* CSS `nth` pseudo-classes now handle spaces, e.g. `"2n + 1"`. [#3018] (@fusion2004)
* `libgumbo` no longer leaks memory when an incomplete tag is abandoned by the HTML5 parser. [#3036] (@flavorjones)

### Removed

* Removed `Nokogiri::HTML5.get` which was deprecated in v1.12.0. [#2278] (@flavorjones)
* Removed the CSS-to-XPath utility modules `XPathVisitorAlwaysUseBuiltins` and `XPathVisitorOptimallyUseBuiltins`, which were deprecated in v1.13.0 in favor of `XPathVisitor` constructor args. [#2403] (@flavorjones)
* Removed `XML::Reader#attribute_nodes` which was deprecated in v1.13.8 in favor of `#attribute_hash`. [#2598, #2599] (@flavorjones)


## 1.15.5 / 2023-11-17

Expand Down
3 changes: 1 addition & 2 deletions ext/java/nokogiri/XmlCdata.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public class XmlCdata extends XmlText
throw context.runtime.newTypeError(msg);
}
if (!(rbDocument instanceof XmlDocument)) {
// TODO: deprecate allowing Node
context.runtime.getWarnings().warn("Passing a Node as the first parameter to CDATA.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
context.runtime.getWarnings().warn("Passing a Node as the first parameter to CDATA.new is deprecated. Please pass a Document instead. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.15.3, remove in v1.17.0
}

Document document = ((XmlNode) rbDocument).getOwnerDocument();
Expand Down
3 changes: 1 addition & 2 deletions ext/java/nokogiri/XmlNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ public class XmlNode extends RubyObject
throw context.runtime.newArgumentError("document must be a Nokogiri::XML::Node");
}
if (!(doc instanceof XmlDocument)) {
// TODO: deprecate allowing Node
context.runtime.getWarnings().warn("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in a future release of Nokogiri.");
context.runtime.getWarnings().warn("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.13.0, remove in v1.17.0
}

Document document = asXmlNode(context, doc).getOwnerDocument();
Expand Down
8 changes: 0 additions & 8 deletions ext/java/nokogiri/XmlReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@ public class XmlReader extends RubyObject
return currentNode().getAttributeCount();
}

@JRubyMethod
public IRubyObject
attribute_nodes(ThreadContext context)
{
context.runtime.getWarnings().warn("Reader#attribute_nodes is deprecated and will be removed in a future version of Nokogiri. Please use Reader#attribute_hash instead.");
return currentNode().getAttributesNodes();
}

@JRubyMethod
public IRubyObject
attribute_hash(ThreadContext context)
Expand Down
3 changes: 1 addition & 2 deletions ext/java/nokogiri/XmlSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ public class XmlSchema extends RubyObject
throw context.runtime.newTypeError(msg);
}
if (!(rbDocument instanceof XmlDocument)) {
// TODO: deprecate allowing Node
context.runtime.getWarnings().warn("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
context.runtime.getWarnings().warn("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.15.3, remove in v1.17.0
}

XmlDocument doc = ((XmlDocument)((XmlNode) rbDocument).document(context));
Expand Down
3 changes: 1 addition & 2 deletions ext/java/nokogiri/XmlText.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public class XmlText extends XmlNode
throw context.runtime.newTypeError(msg);
}
if (!(rbDocument instanceof XmlDocument)) {
// TODO: deprecate allowing Node
context.runtime.getWarnings().warn("Passing a Node as the second parameter to Text.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
context.runtime.getWarnings().warn("Passing a Node as the second parameter to Text.new is deprecated. Please pass a Document instead. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.15.3, remove in v1.17.0
}

Document document = asXmlNode(context, rbDocument).getOwnerDocument();
Expand Down
3 changes: 1 addition & 2 deletions ext/nokogiri/xml_cdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ rb_xml_cdata_s_new(int argc, VALUE *argv, VALUE klass)

if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
xmlNodePtr deprecated_node_type_arg;
// TODO: deprecate allowing Node
NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to CDATA.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to CDATA.new is deprecated. Please pass a Document instead. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.15.3, remove in v1.17.0
Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg);
c_document = deprecated_node_type_arg->doc;
} else {
Expand Down
3 changes: 1 addition & 2 deletions ext/nokogiri/xml_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -2054,8 +2054,7 @@ rb_xml_node_new(int argc, VALUE *argv, VALUE klass)
rb_raise(rb_eArgError, "document must be a Nokogiri::XML::Node");
}
if (!rb_obj_is_kind_of(rb_document_node, cNokogiriXmlDocument)) {
// TODO: deprecate allowing Node
NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in a future release of Nokogiri.");
NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.13.0, remove in v1.17.0
}
Noko_Node_Get_Struct(rb_document_node, xmlNode, c_document_node);

Expand Down
43 changes: 0 additions & 43 deletions ext/nokogiri/xml_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,48 +166,6 @@ rb_xml_reader_namespaces(VALUE rb_reader)
return rb_namespaces ;
}

/*
:call-seq: attribute_nodes() → Array<Nokogiri::XML::Attr>
Get the attributes of the current node as an Array of XML:Attr
⚠ This method is deprecated and unsafe to use. It will be removed in a future version of Nokogiri.
See related: #attribute_hash, #attributes
*/
static VALUE
rb_xml_reader_attribute_nodes(VALUE rb_reader)
{
xmlTextReaderPtr c_reader;
xmlNodePtr c_node;
VALUE attr_nodes;
int j;

// TODO: deprecated, remove in Nokogiri v1.15, see https://github.com/sparklemotion/nokogiri/issues/2598
// After removal, we can also remove all the "node_has_a_document" special handling from xml_node.c
NOKO_WARN_DEPRECATION("Reader#attribute_nodes is deprecated and will be removed in a future version of Nokogiri. Please use Reader#attribute_hash instead.");

TypedData_Get_Struct(rb_reader, xmlTextReader, &xml_reader_type, c_reader);

if (! has_attributes(c_reader)) {
return rb_ary_new() ;
}

c_node = xmlTextReaderExpand(c_reader);
if (c_node == NULL) {
return Qnil;
}

attr_nodes = noko_xml_node_attrs(c_node);

/* ensure that the Reader won't be GCed as long as a node is referenced */
for (j = 0 ; j < RARRAY_LEN(attr_nodes) ; j++) {
rb_iv_set(rb_ary_entry(attr_nodes, j), "@reader", rb_reader);
}

return attr_nodes;
}

/*
:call-seq: attribute_hash() → Hash<String ⇒ String>
Expand Down Expand Up @@ -778,7 +736,6 @@ noko_init_xml_reader(void)
rb_define_method(cNokogiriXmlReader, "attribute", reader_attribute, 1);
rb_define_method(cNokogiriXmlReader, "attribute_at", attribute_at, 1);
rb_define_method(cNokogiriXmlReader, "attribute_count", attribute_count, 0);
rb_define_method(cNokogiriXmlReader, "attribute_nodes", rb_xml_reader_attribute_nodes, 0);
rb_define_method(cNokogiriXmlReader, "attribute_hash", rb_xml_reader_attribute_hash, 0);
rb_define_method(cNokogiriXmlReader, "attributes?", attributes_eh, 0);
rb_define_method(cNokogiriXmlReader, "base_uri", rb_xml_reader_base_uri, 0);
Expand Down
3 changes: 1 addition & 2 deletions ext/nokogiri/xml_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ rb_xml_schema_s_from_document(int argc, VALUE *argv, VALUE klass)

if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
xmlNodePtr deprecated_node_type_arg;
// TODO: deprecate allowing Node
NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.15.3, remove in v1.17.0
Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg);
c_document = deprecated_node_type_arg->doc;
} else {
Expand Down
3 changes: 1 addition & 2 deletions ext/nokogiri/xml_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ rb_xml_text_s_new(int argc, VALUE *argv, VALUE klass)

if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
xmlNodePtr deprecated_node_type_arg;
// TODO: deprecate allowing Node
NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Text.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Text.new is deprecated. Please pass a Document instead. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.15.3, remove in v1.17.0
Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg);
c_document = deprecated_node_type_arg->doc;
} else {
Expand Down
7 changes: 2 additions & 5 deletions ext/nokogiri/xml_xpath_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,8 @@ handler_lookup(void *data, const xmlChar *c_name, const xmlChar *c_ns_uri)
VALUE rb_handler = (VALUE)data;
if (rb_respond_to(rb_handler, rb_intern((const char *)c_name))) {
if (c_ns_uri == NULL) {
NOKO_WARN_DEPRECATION(
"A custom XPath or CSS handler function named '%s' is being invoked without a namespace."
" Please update your query to reference this function as 'nokogiri:%s'."
" Invoking custom handler functions without a namespace is deprecated and support will be removed in a future release of Nokogiri.",
c_name, c_name);
NOKO_WARN_DEPRECATION("A custom XPath or CSS handler function named '%s' is being invoked without a namespace. Please update your query to reference this function as 'nokogiri:%s'. Invoking custom handler functions without a namespace is deprecated and will become an error in Nokogiri v1.17.0.",
c_name, c_name); // deprecated in v1.15.0, remove in v1.17.0
}
return method_caller;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/nokogiri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def Slop(*args, &block)

# :nodoc:
def install_default_aliases
warn("Nokogiri.install_default_aliases is deprecated and will be removed in a future version of Nokogiri. Please call Nokogiri::EncodingHandler.install_default_aliases instead.")
warn("Nokogiri.install_default_aliases is deprecated. Please call Nokogiri::EncodingHandler.install_default_aliases instead. This will become an error in Nokogiri v1.17.0.", uplevel: 1, category: :deprecated) # deprecated in v1.14.0, remove in v1.17.0
Nokogiri::EncodingHandler.install_default_aliases
end
end
Expand Down
20 changes: 0 additions & 20 deletions lib/nokogiri/css/xpath_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,25 +335,5 @@ def css_class(hay, needle)
end
end
end

module XPathVisitorAlwaysUseBuiltins # :nodoc:
def self.new
warn(
"Nokogiri::CSS::XPathVisitorAlwaysUseBuiltins is deprecated and will be removed in a future version of Nokogiri",
{ uplevel: 1 },
)
XPathVisitor.new(builtins: :always)
end
end

module XPathVisitorOptimallyUseBuiltins # :nodoc:
def self.new
warn(
"Nokogiri::CSS::XPathVisitorOptimallyUseBuiltins is deprecated and will be removed in a future version of Nokogiri",
{ uplevel: 1 },
)
XPathVisitor.new(builtins: :optimal)
end
end
end
end
66 changes: 0 additions & 66 deletions lib/nokogiri/html5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,23 +239,6 @@ def fragment(string, encoding = nil, **options)
DocumentFragment.parse(string, encoding, options)
end

# Fetch and parse a HTML document from the web, following redirects,
# handling https, and determining the character encoding using HTML5
# rules. +uri+ may be a +String+ or a +URI+. +options+ contains
# http headers and special options. Everything which is not a
# special option is considered a header. Special options include:
# * :follow_limit => number of redirects which are followed
# * :basic_auth => [username, password]
def get(uri, options = {})
# TODO: deprecate
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

# :nodoc:
def read_and_encode(string, encoding)
# Read the string with the given encoding.
Expand Down Expand Up @@ -283,55 +266,6 @@ def read_and_encode(string, encoding)

private

def 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

require "net/http"
uri = URI(uri) unless URI === uri

http = Net::HTTP.new(uri.host, uri.port)

# TLS / SSL support
http.use_ssl = true if uri.scheme == "https"

# Pass through Net::HTTP override values, which currently include:
# :ca_file, :ca_path, :cert, :cert_store, :ciphers,
# :close_on_empty_response, :continue_timeout, :key, :open_timeout,
# :read_timeout, :ssl_timeout, :ssl_version, :use_ssl,
# :verify_callback, :verify_depth, :verify_mode
options.each do |key, _value|
http.send("#{key}=", headers.delete(key)) if http.respond_to?("#{key}=")
end

request = Net::HTTP::Get.new(uri.request_uri)

# basic authentication
auth = headers.delete(:basic_auth)
auth ||= [uri.user, uri.password] if uri.user && uri.password
request.basic_auth(auth.first, auth.last) if auth

# remaining options are treated as headers
headers.each { |key, value| request[key.to_s] = value.to_s }

response = http.request(request)

case response
when Net::HTTPSuccess
doc = parse(reencode(response.body, response["content-type"]), options)
doc.instance_variable_set(:@response, response)
doc.class.send(:attr_reader, :response)
doc
when Net::HTTPRedirection
response.value if limit <= 1
location = URI.join(uri, response["location"])
get_impl(location, options.merge(follow_limit: limit - 1))
else
response.value
end
end

# Charset sniffing is a complex and controversial topic that understandably isn't done _by
# default_ by the Ruby Net::HTTP library. This being said, it is a very real problem for
# consumers of HTML as the default for HTML is iso-8859-1, most "good" producers use utf-8, and
Expand Down
37 changes: 0 additions & 37 deletions test/css/test_xpath_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -567,21 +567,6 @@ def visit_pseudo_class_aaron(node)
parser.parse("a[@data-words~=\"bar\"]"),
)
end

describe "XPathVisitorAlwaysUseBuiltins" do
let(:visitor) { Nokogiri::CSS::XPathVisitorAlwaysUseBuiltins.new }

it "supports deprecated class" do
assert_output("", /XPathVisitorAlwaysUseBuiltins is deprecated/) { visitor }
assert_instance_of(Nokogiri::CSS::XPathVisitor, visitor)
assert_equal({ builtins: Nokogiri::CSS::XPathVisitor::BuiltinsConfig::ALWAYS, doctype: Nokogiri::CSS::XPathVisitor::DoctypeConfig::XML }, visitor.config)

assert_xpath(
"//*[nokogiri-builtin:css-class(@class,'awesome')]",
parser.parse(".awesome"),
)
end
end
end

describe "builtins:optimal" do
Expand Down Expand Up @@ -658,28 +643,6 @@ def visit_pseudo_class_aaron(node)
)
end
end

describe "XPathVisitorOptimallyUseBuiltins" do
let(:visitor) { Nokogiri::CSS::XPathVisitorOptimallyUseBuiltins.new }

it "supports deprecated class" do
assert_output("", /XPathVisitorOptimallyUseBuiltins is deprecated/) { visitor }
assert_instance_of(Nokogiri::CSS::XPathVisitor, visitor)
assert_equal({ builtins: Nokogiri::CSS::XPathVisitor::BuiltinsConfig::OPTIMAL, doctype: Nokogiri::CSS::XPathVisitor::DoctypeConfig::XML }, visitor.config)

if Nokogiri.uses_libxml?
assert_xpath(
"//*[nokogiri-builtin:css-class(@class,'awesome')]",
parser.parse(".awesome"),
)
else
assert_xpath(
"//*[contains(concat(' ',normalize-space(@class),' '),' awesome ')]",
parser.parse(".awesome"),
)
end
end
end
end

#
Expand Down
Loading

0 comments on commit def3710

Please sign in to comment.