nokogiri 1.16.8-x86_64-linux → 1.17.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +11 -21
  3. data/README.md +4 -0
  4. data/dependencies.yml +6 -6
  5. data/ext/nokogiri/extconf.rb +191 -137
  6. data/ext/nokogiri/gumbo.c +69 -53
  7. data/ext/nokogiri/html4_document.c +10 -4
  8. data/ext/nokogiri/html4_element_description.c +18 -18
  9. data/ext/nokogiri/html4_sax_parser.c +40 -0
  10. data/ext/nokogiri/html4_sax_parser_context.c +48 -58
  11. data/ext/nokogiri/html4_sax_push_parser.c +25 -24
  12. data/ext/nokogiri/include/libexslt/exsltconfig.h +3 -3
  13. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +12 -19
  14. data/ext/nokogiri/include/libxml2/libxml/c14n.h +1 -12
  15. data/ext/nokogiri/include/libxml2/libxml/debugXML.h +1 -1
  16. data/ext/nokogiri/include/libxml2/libxml/encoding.h +9 -0
  17. data/ext/nokogiri/include/libxml2/libxml/entities.h +12 -1
  18. data/ext/nokogiri/include/libxml2/libxml/hash.h +19 -0
  19. data/ext/nokogiri/include/libxml2/libxml/list.h +2 -2
  20. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +17 -0
  21. data/ext/nokogiri/include/libxml2/libxml/parser.h +60 -54
  22. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +9 -1
  23. data/ext/nokogiri/include/libxml2/libxml/pattern.h +6 -0
  24. data/ext/nokogiri/include/libxml2/libxml/tree.h +32 -12
  25. data/ext/nokogiri/include/libxml2/libxml/uri.h +11 -0
  26. data/ext/nokogiri/include/libxml2/libxml/valid.h +29 -2
  27. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +7 -0
  28. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +21 -4
  29. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +14 -0
  30. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +111 -15
  31. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +8 -45
  32. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +2 -0
  33. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +5 -0
  34. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +165 -1
  35. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +7 -171
  36. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +1 -0
  37. data/ext/nokogiri/include/libxml2/libxml/xpath.h +4 -0
  38. data/ext/nokogiri/include/libxslt/xsltInternals.h +3 -0
  39. data/ext/nokogiri/include/libxslt/xsltconfig.h +4 -37
  40. data/ext/nokogiri/libxml2_polyfill.c +114 -0
  41. data/ext/nokogiri/nokogiri.c +9 -2
  42. data/ext/nokogiri/nokogiri.h +18 -33
  43. data/ext/nokogiri/xml_attr.c +1 -1
  44. data/ext/nokogiri/xml_cdata.c +2 -10
  45. data/ext/nokogiri/xml_comment.c +3 -8
  46. data/ext/nokogiri/xml_document.c +163 -156
  47. data/ext/nokogiri/xml_document_fragment.c +10 -25
  48. data/ext/nokogiri/xml_dtd.c +1 -1
  49. data/ext/nokogiri/xml_element_content.c +9 -9
  50. data/ext/nokogiri/xml_encoding_handler.c +4 -4
  51. data/ext/nokogiri/xml_namespace.c +6 -6
  52. data/ext/nokogiri/xml_node.c +130 -104
  53. data/ext/nokogiri/xml_node_set.c +46 -44
  54. data/ext/nokogiri/xml_reader.c +54 -58
  55. data/ext/nokogiri/xml_relax_ng.c +35 -56
  56. data/ext/nokogiri/xml_sax_parser.c +156 -88
  57. data/ext/nokogiri/xml_sax_parser_context.c +213 -131
  58. data/ext/nokogiri/xml_sax_push_parser.c +68 -49
  59. data/ext/nokogiri/xml_schema.c +50 -85
  60. data/ext/nokogiri/xml_syntax_error.c +19 -11
  61. data/ext/nokogiri/xml_text.c +2 -4
  62. data/ext/nokogiri/xml_xpath_context.c +2 -2
  63. data/ext/nokogiri/xslt_stylesheet.c +8 -8
  64. data/lib/nokogiri/3.0/nokogiri.so +0 -0
  65. data/lib/nokogiri/3.1/nokogiri.so +0 -0
  66. data/lib/nokogiri/3.2/nokogiri.so +0 -0
  67. data/lib/nokogiri/3.3/nokogiri.so +0 -0
  68. data/lib/nokogiri/class_resolver.rb +1 -1
  69. data/lib/nokogiri/css/node.rb +6 -2
  70. data/lib/nokogiri/css/parser.rb +6 -4
  71. data/lib/nokogiri/css/parser.y +2 -2
  72. data/lib/nokogiri/css/parser_extras.rb +6 -66
  73. data/lib/nokogiri/css/selector_cache.rb +38 -0
  74. data/lib/nokogiri/css/tokenizer.rb +4 -4
  75. data/lib/nokogiri/css/tokenizer.rex +9 -8
  76. data/lib/nokogiri/css/xpath_visitor.rb +42 -6
  77. data/lib/nokogiri/css.rb +86 -20
  78. data/lib/nokogiri/decorators/slop.rb +3 -5
  79. data/lib/nokogiri/encoding_handler.rb +2 -2
  80. data/lib/nokogiri/html4/document.rb +44 -23
  81. data/lib/nokogiri/html4/document_fragment.rb +124 -12
  82. data/lib/nokogiri/html4/encoding_reader.rb +1 -1
  83. data/lib/nokogiri/html4/sax/parser.rb +23 -38
  84. data/lib/nokogiri/html4/sax/parser_context.rb +4 -9
  85. data/lib/nokogiri/html4.rb +9 -14
  86. data/lib/nokogiri/html5/builder.rb +40 -0
  87. data/lib/nokogiri/html5/document.rb +61 -30
  88. data/lib/nokogiri/html5/document_fragment.rb +130 -20
  89. data/lib/nokogiri/html5/node.rb +4 -4
  90. data/lib/nokogiri/html5.rb +114 -72
  91. data/lib/nokogiri/version/constant.rb +1 -1
  92. data/lib/nokogiri/xml/builder.rb +8 -1
  93. data/lib/nokogiri/xml/document.rb +70 -26
  94. data/lib/nokogiri/xml/document_fragment.rb +84 -13
  95. data/lib/nokogiri/xml/node.rb +82 -11
  96. data/lib/nokogiri/xml/node_set.rb +9 -7
  97. data/lib/nokogiri/xml/parse_options.rb +1 -1
  98. data/lib/nokogiri/xml/pp/node.rb +6 -1
  99. data/lib/nokogiri/xml/reader.rb +46 -13
  100. data/lib/nokogiri/xml/relax_ng.rb +57 -20
  101. data/lib/nokogiri/xml/sax/document.rb +174 -83
  102. data/lib/nokogiri/xml/sax/parser.rb +115 -41
  103. data/lib/nokogiri/xml/sax/parser_context.rb +116 -8
  104. data/lib/nokogiri/xml/sax/push_parser.rb +3 -0
  105. data/lib/nokogiri/xml/sax.rb +48 -0
  106. data/lib/nokogiri/xml/schema.rb +112 -45
  107. data/lib/nokogiri/xml/searchable.rb +6 -8
  108. data/lib/nokogiri/xml/syntax_error.rb +22 -0
  109. data/lib/nokogiri/xml.rb +13 -24
  110. data/lib/nokogiri/xslt.rb +3 -9
  111. data/lib/xsd/xmlparser/nokogiri.rb +3 -4
  112. metadata +8 -4
  113. data/ext/nokogiri/libxml2_backwards_compat.c +0 -121
@@ -4,15 +4,123 @@ module Nokogiri
4
4
  module XML
5
5
  module SAX
6
6
  ###
7
- # Context for XML SAX parsers. This class is usually not instantiated
8
- # by the user. Instead, you should be looking at
9
- # Nokogiri::XML::SAX::Parser
7
+ # Context object to invoke the XML SAX parser on the SAX::Document handler.
8
+ #
9
+ # 💡 This class is usually not instantiated by the user. Use Nokogiri::XML::SAX::Parser
10
+ # instead.
10
11
  class ParserContext
11
- def self.new(thing, encoding = "UTF-8")
12
- if [:read, :close].all? { |x| thing.respond_to?(x) }
13
- io(thing, Parser::ENCODINGS[encoding])
14
- else
15
- memory(thing)
12
+ class << self
13
+ ###
14
+ # :call-seq:
15
+ # new(input)
16
+ # new(input, encoding)
17
+ #
18
+ # Create a parser context for an IO or a String. This is a shorthand method for
19
+ # ParserContext.io and ParserContext.memory.
20
+ #
21
+ # [Parameters]
22
+ # - +input+ (IO, String) A String or a readable IO object
23
+ # - +encoding+ (optional) (Encoding) The +Encoding+ to use, or the name of an
24
+ # encoding to use (default +nil+, encoding will be autodetected)
25
+ #
26
+ # If +input+ quacks like a readable IO object, this method forwards to ParserContext.io,
27
+ # otherwise it forwards to ParserContext.memory.
28
+ #
29
+ # [Returns] Nokogiri::XML::SAX::ParserContext
30
+ #
31
+ def new(input, encoding = nil)
32
+ if [:read, :close].all? { |x| input.respond_to?(x) }
33
+ io(input, encoding)
34
+ else
35
+ memory(input, encoding)
36
+ end
37
+ end
38
+
39
+ ###
40
+ # :call-seq:
41
+ # io(input)
42
+ # io(input, encoding)
43
+ #
44
+ # Create a parser context for an +input+ IO which will assume +encoding+
45
+ #
46
+ # [Parameters]
47
+ # - +io+ (IO) The readable IO object from which to read input
48
+ # - +encoding+ (optional) (Encoding) The +Encoding+ to use, or the name of an
49
+ # encoding to use (default +nil+, encoding will be autodetected)
50
+ #
51
+ # [Returns] Nokogiri::XML::SAX::ParserContext
52
+ #
53
+ # 💡 Calling this method directly is discouraged. Use Nokogiri::XML::SAX::Parser parse
54
+ # methods which are more convenient for most use cases.
55
+ #
56
+ def io(input, encoding = nil)
57
+ native_io(input, resolve_encoding(encoding))
58
+ end
59
+
60
+ ###
61
+ # :call-seq:
62
+ # memory(input)
63
+ # memory(input, encoding)
64
+ #
65
+ # Create a parser context for the +input+ String.
66
+ #
67
+ # [Parameters]
68
+ # - +input+ (String) The input string to be parsed.
69
+ # - +encoding+ (optional) (Encoding, String) The +Encoding+ to use, or the name of an encoding to
70
+ # use (default +nil+, encoding will be autodetected)
71
+ #
72
+ # [Returns] Nokogiri::XML::SAX::ParserContext
73
+ #
74
+ # 💡 Calling this method directly is discouraged. Use Nokogiri::XML::SAX::Parser parse methods
75
+ # which are more convenient for most use cases.
76
+ #
77
+ def memory(input, encoding = nil)
78
+ native_memory(input, resolve_encoding(encoding))
79
+ end
80
+
81
+ ###
82
+ # :call-seq:
83
+ # file(path)
84
+ # file(path, encoding)
85
+ #
86
+ # Create a parser context for the file at +path+.
87
+ #
88
+ # [Parameters]
89
+ # - +path+ (String) The path to the input file
90
+ # - +encoding+ (optional) (Encoding, String) The +Encoding+ to use, or the name of an encoding to
91
+ # use (default +nil+, encoding will be autodetected)
92
+ #
93
+ # [Returns] Nokogiri::XML::SAX::ParserContext
94
+ #
95
+ # 💡 Calling this method directly is discouraged. Use Nokogiri::XML::SAX::Parser.parse_file which
96
+ # is more convenient for most use cases.
97
+ def file(input, encoding = nil)
98
+ native_file(input, resolve_encoding(encoding))
99
+ end
100
+
101
+ private def resolve_encoding(encoding)
102
+ case encoding
103
+ when Encoding
104
+ encoding
105
+
106
+ when nil
107
+ nil # totally fine, parser will guess encoding
108
+
109
+ when Integer
110
+ warn("Passing an integer to Nokogiri::XML::SAX::ParserContext.io is deprecated. Use an Encoding object instead. This will become an error in a future release.", uplevel: 2, category: :deprecated)
111
+
112
+ return nil if encoding == Parser::ENCODINGS["NONE"]
113
+
114
+ encoding = Parser::REVERSE_ENCODINGS[encoding]
115
+ raise ArgumentError, "Invalid libxml2 encoding id #{encoding}" if encoding.nil?
116
+ Encoding.find(encoding)
117
+
118
+ when String
119
+ Encoding.find(encoding)
120
+
121
+ else
122
+ raise ArgumentError, "Cannot resolve #{encoding.inspect} to an Encoding"
123
+ end
16
124
  end
17
125
  end
18
126
  end
@@ -52,6 +52,9 @@ module Nokogiri
52
52
  ###
53
53
  # Finish the parsing. This method is only necessary for
54
54
  # Nokogiri::XML::SAX::Document#end_document to be called.
55
+ #
56
+ # ⚠ Note that empty documents are treated as an error when using the libxml2-based
57
+ # implementation (CRuby), but are fine when using the Xerces-based implementation (JRuby).
55
58
  def finish
56
59
  write("", true)
57
60
  end
@@ -1,5 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ module Nokogiri
4
+ module XML
5
+ ###
6
+ # SAX Parsers are event-driven parsers.
7
+ #
8
+ # Two SAX parsers for XML are available, a parser that reads from a string or IO object as it
9
+ # feels necessary, and a parser that you explicitly feed XML in chunks. If you want to let
10
+ # Nokogiri deal with reading your XML, use the Nokogiri::XML::SAX::Parser. If you want to have
11
+ # fine grain control over the XML input, use the Nokogiri::XML::SAX::PushParser.
12
+ #
13
+ # If you want to do SAX style parsing of HTML, check out Nokogiri::HTML4::SAX.
14
+ #
15
+ # The basic way a SAX style parser works is by creating a parser, telling the parser about the
16
+ # events we're interested in, then giving the parser some XML to process. The parser will notify
17
+ # you when it encounters events you said you would like to know about.
18
+ #
19
+ # To register for events, subclass Nokogiri::XML::SAX::Document and implement the methods for
20
+ # which you would like notification.
21
+ #
22
+ # For example, if I want to be notified when a document ends, and when an element starts, I
23
+ # would write a class like this:
24
+ #
25
+ # class MyHandler < Nokogiri::XML::SAX::Document
26
+ # def end_document
27
+ # puts "the document has ended"
28
+ # end
29
+ #
30
+ # def start_element name, attributes = []
31
+ # puts "#{name} started"
32
+ # end
33
+ # end
34
+ #
35
+ # Then I would instantiate a SAX parser with this document, and feed the parser some XML
36
+ #
37
+ # # Create a new parser
38
+ # parser = Nokogiri::XML::SAX::Parser.new(MyHandler.new)
39
+ #
40
+ # # Feed the parser some XML
41
+ # parser.parse(File.open(ARGV[0]))
42
+ #
43
+ # Now my document handler will be called when each node starts, and when then document ends. To
44
+ # see what kinds of events are available, take a look at Nokogiri::XML::SAX::Document.
45
+ #
46
+ module SAX
47
+ end
48
+ end
49
+ end
50
+
3
51
  require_relative "sax/document"
4
52
  require_relative "sax/parser_context"
5
53
  require_relative "sax/parser"
@@ -3,70 +3,137 @@
3
3
  module Nokogiri
4
4
  module XML
5
5
  class << self
6
- ###
7
- # Create a new Nokogiri::XML::Schema object using a +string_or_io+
8
- # object.
9
- def Schema(string_or_io, options = ParseOptions::DEFAULT_SCHEMA)
10
- Schema.new(string_or_io, options)
6
+ # :call-seq:
7
+ # Schema(input) Nokogiri::XML::Schema
8
+ # Schema(input, parse_options) → Nokogiri::XML::Schema
9
+ #
10
+ # Convenience method for Nokogiri::XML::Schema.new
11
+ def Schema(...)
12
+ Schema.new(...)
11
13
  end
12
14
  end
13
15
 
14
- ###
15
- # Nokogiri::XML::Schema is used for validating XML against a schema
16
- # (usually from an xsd file).
16
+ # Nokogiri::XML::Schema is used for validating \XML against an \XSD schema definition.
17
17
  #
18
- # == Synopsis
18
+ # Since v1.11.0, Schema treats inputs as *untrusted* by default, and so external entities are
19
+ # not resolved from the network (+http://+ or +ftp://+). When parsing a trusted document, the
20
+ # caller may turn off the +NONET+ option via the ParseOptions to (re-)enable external entity
21
+ # resolution over a network connection.
19
22
  #
20
- # Validate an XML document against a Schema. Loop over the errors that
21
- # are returned and print them out:
23
+ # 🛡 Before v1.11.0, documents were "trusted" by default during schema parsing which was counter
24
+ # to Nokogiri's "untrusted by default" security policy.
22
25
  #
23
- # xsd = Nokogiri::XML::Schema(File.read(PO_SCHEMA_FILE))
24
- # doc = Nokogiri::XML(File.read(PO_XML_FILE))
26
+ # *Example:* Determine whether an \XML document is valid.
25
27
  #
26
- # xsd.validate(doc).each do |error|
27
- # puts error.message
28
- # end
28
+ # schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))
29
+ # doc = Nokogiri::XML::Document.parse(File.read(XML_FILE))
30
+ # schema.valid?(doc) # Boolean
29
31
  #
30
- # The list of errors are Nokogiri::XML::SyntaxError objects.
32
+ # *Example:* Validate an \XML document against an \XSD schema, and capture any errors that are found.
33
+ #
34
+ # schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))
35
+ # doc = Nokogiri::XML::Document.parse(File.read(XML_FILE))
36
+ # errors = schema.validate(doc) # Array<SyntaxError>
37
+ #
38
+ # *Example:* Validate an \XML document using a Document containing an \XSD schema definition.
39
+ #
40
+ # schema_doc = Nokogiri::XML::Document.parse(File.read(RELAX_NG_FILE))
41
+ # schema = Nokogiri::XML::Schema.from_document(schema_doc)
42
+ # doc = Nokogiri::XML::Document.parse(File.read(XML_FILE))
43
+ # schema.valid?(doc) # Boolean
31
44
  #
32
- # NOTE: As of v1.11.0, Schema treats inputs as UNTRUSTED by default, and so external entities
33
- # are not resolved from the network (`http://` or `ftp://`). Previously, parsing treated
34
- # documents as "trusted" by default which was counter to Nokogiri's "untrusted by default"
35
- # security policy. If a document is trusted, then the caller may turn off the NONET option via
36
- # the ParseOptions to re-enable external entity resolution over a network connection.
37
45
  class Schema
38
- # Errors while parsing the schema file
46
+ # The errors found while parsing the \XSD
47
+ #
48
+ # [Returns] Array<Nokogiri::XML::SyntaxError>
39
49
  attr_accessor :errors
40
- # The Nokogiri::XML::ParseOptions used to parse the schema
50
+
51
+ # The options used to parse the schema
52
+ #
53
+ # [Returns] Nokogiri::XML::ParseOptions
41
54
  attr_accessor :parse_options
42
55
 
43
- ###
44
- # Create a new Nokogiri::XML::Schema object using a +string_or_io+
45
- # object.
46
- def self.new(string_or_io, options = ParseOptions::DEFAULT_SCHEMA)
47
- from_document(Nokogiri::XML(string_or_io), options)
56
+ # :call-seq:
57
+ # new(input) Nokogiri::XML::Schema
58
+ # new(input, parse_options) → Nokogiri::XML::Schema
59
+ #
60
+ # Parse an \XSD schema definition from a String or IO to create a new Nokogiri::XML::Schema
61
+ #
62
+ # [Parameters]
63
+ # - +input+ (String | IO) \XSD schema definition
64
+ # - +parse_options+ (Nokogiri::XML::ParseOptions)
65
+ # Defaults to Nokogiri::XML::ParseOptions::DEFAULT_SCHEMA
66
+ #
67
+ # [Returns] Nokogiri::XML::Schema
68
+ #
69
+ def self.new(input, parse_options_ = ParseOptions::DEFAULT_SCHEMA, parse_options: parse_options_)
70
+ from_document(Nokogiri::XML::Document.parse(input), parse_options)
71
+ end
72
+
73
+ # :call-seq:
74
+ # read_memory(input) → Nokogiri::XML::Schema
75
+ # read_memory(input, parse_options) → Nokogiri::XML::Schema
76
+ #
77
+ # Convenience method for Nokogiri::XML::Schema.new
78
+ def self.read_memory(...)
79
+ # TODO deprecate this method
80
+ new(...)
48
81
  end
49
82
 
50
- ###
51
- # Validate +thing+ against this schema. +thing+ can be a
52
- # Nokogiri::XML::Document object, or a filename. An Array of
53
- # Nokogiri::XML::SyntaxError objects found while validating the
54
- # +thing+ is returned.
55
- def validate(thing)
56
- if thing.is_a?(Nokogiri::XML::Document)
57
- validate_document(thing)
58
- elsif File.file?(thing)
59
- validate_file(thing)
83
+ #
84
+ # :call-seq: validate(input) Array<SyntaxError>
85
+ #
86
+ # Validate +input+ and return any errors that are found.
87
+ #
88
+ # [Parameters]
89
+ # - +input+ (Nokogiri::XML::Document | String)
90
+ # A parsed document, or a string containing a local filename.
91
+ #
92
+ # [Returns] Array<SyntaxError>
93
+ #
94
+ # *Example:* Validate an existing XML::Document, and capture any errors that are found.
95
+ #
96
+ # schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))
97
+ # errors = schema.validate(document)
98
+ #
99
+ # *Example:* Validate an \XML document on disk, and capture any errors that are found.
100
+ #
101
+ # schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))
102
+ # errors = schema.validate("/path/to/file.xml")
103
+ #
104
+ def validate(input)
105
+ if input.is_a?(Nokogiri::XML::Document)
106
+ validate_document(input)
107
+ elsif File.file?(input)
108
+ validate_file(input)
60
109
  else
61
- raise ArgumentError, "Must provide Nokogiri::Xml::Document or the name of an existing file"
110
+ raise ArgumentError, "Must provide Nokogiri::XML::Document or the name of an existing file"
62
111
  end
63
112
  end
64
113
 
65
- ###
66
- # Returns true if +thing+ is a valid Nokogiri::XML::Document or
67
- # file.
68
- def valid?(thing)
69
- validate(thing).empty?
114
+ #
115
+ # :call-seq: valid?(input) Boolean
116
+ #
117
+ # Validate +input+ and return a Boolean indicating whether the document is valid
118
+ #
119
+ # [Parameters]
120
+ # - +input+ (Nokogiri::XML::Document | String)
121
+ # A parsed document, or a string containing a local filename.
122
+ #
123
+ # [Returns] Boolean
124
+ #
125
+ # *Example:* Validate an existing XML::Document
126
+ #
127
+ # schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))
128
+ # return unless schema.valid?(document)
129
+ #
130
+ # *Example:* Validate an \XML document on disk
131
+ #
132
+ # schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))
133
+ # return unless schema.valid?("/path/to/file.xml")
134
+ #
135
+ def valid?(input)
136
+ validate(input).empty?
70
137
  end
71
138
  end
72
139
  end
@@ -243,16 +243,14 @@ module Nokogiri
243
243
  end
244
244
 
245
245
  def xpath_query_from_css_rule(rule, ns)
246
- visitor = Nokogiri::CSS::XPathVisitor.new(
247
- builtins: Nokogiri::CSS::XPathVisitor::BuiltinsConfig::OPTIMAL,
248
- doctype: document.xpath_doctype,
249
- )
250
246
  self.class::IMPLIED_XPATH_CONTEXTS.map do |implied_xpath_context|
251
- CSS.xpath_for(rule.to_s, {
247
+ visitor = Nokogiri::CSS::XPathVisitor.new(
248
+ builtins: Nokogiri::CSS::XPathVisitor::BuiltinsConfig::OPTIMAL,
249
+ doctype: document.xpath_doctype,
252
250
  prefix: implied_xpath_context,
253
- ns: ns,
254
- visitor: visitor,
255
- })
251
+ namespaces: ns,
252
+ )
253
+ CSS.xpath_for(rule.to_s, visitor: visitor)
256
254
  end.join(" | ")
257
255
  end
258
256
 
@@ -6,11 +6,33 @@ module Nokogiri
6
6
  # This class provides information about XML SyntaxErrors. These
7
7
  # exceptions are typically stored on Nokogiri::XML::Document#errors.
8
8
  class SyntaxError < ::Nokogiri::SyntaxError
9
+ class << self
10
+ def aggregate(errors)
11
+ return nil if errors.empty?
12
+ return errors.first if errors.length == 1
13
+
14
+ messages = ["Multiple errors encountered:"]
15
+ errors.each do |error|
16
+ messages << error.to_s
17
+ end
18
+ new(messages.join("\n"))
19
+ end
20
+ end
21
+
9
22
  attr_reader :domain
10
23
  attr_reader :code
11
24
  attr_reader :level
12
25
  attr_reader :file
13
26
  attr_reader :line
27
+
28
+ # The XPath path of the node that caused the error when validating a `Nokogiri::XML::Document`.
29
+ #
30
+ # This attribute will only be non-nil when the error is emitted by `Schema#validate` on
31
+ # Document objects. It will return `nil` for DOM parsing errors and for errors emitted during
32
+ # Schema validation of files.
33
+ #
34
+ # ⚠ `#path` is not supported on JRuby, where it will always return `nil`.
35
+ attr_reader :path
14
36
  attr_reader :str1
15
37
  attr_reader :str2
16
38
  attr_reader :str3
data/lib/nokogiri/xml.rb CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  module Nokogiri
4
4
  class << self
5
- ###
6
- # Parse XML. Convenience method for Nokogiri::XML::Document.parse
7
- def XML(thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT_XML, &block)
8
- Nokogiri::XML::Document.parse(thing, url, encoding, options, &block)
5
+ # Convenience method for Nokogiri::XML::Document.parse
6
+ def XML(...)
7
+ Nokogiri::XML::Document.parse(...)
9
8
  end
10
9
  end
11
10
 
@@ -16,31 +15,21 @@ module Nokogiri
16
15
  XML_C14N_EXCLUSIVE_1_0 = 1
17
16
  # C14N 1.1 spec canonicalization
18
17
  XML_C14N_1_1 = 2
19
- class << self
20
- ###
21
- # Parse an XML document using the Nokogiri::XML::Reader API. See
22
- # Nokogiri::XML::Reader for mor information
23
- def Reader(string_or_io, url = nil, encoding = nil, options = ParseOptions::STRICT)
24
- options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
25
- yield options if block_given?
26
-
27
- if string_or_io.respond_to?(:read)
28
- return Reader.from_io(string_or_io, url, encoding, options.to_i)
29
- end
30
18
 
31
- Reader.from_memory(string_or_io, url, encoding, options.to_i)
19
+ class << self
20
+ # Convenience method for Nokogiri::XML::Reader.new
21
+ def Reader(...)
22
+ Reader.new(...)
32
23
  end
33
24
 
34
- ###
35
- # Parse XML. Convenience method for Nokogiri::XML::Document.parse
36
- def parse(thing, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML, &block)
37
- Document.parse(thing, url, encoding, options, &block)
25
+ # Convenience method for Nokogiri::XML::Document.parse
26
+ def parse(...)
27
+ Document.parse(...)
38
28
  end
39
29
 
40
- ####
41
- # Parse a fragment from +string+ in to a NodeSet.
42
- def fragment(string, options = ParseOptions::DEFAULT_XML, &block)
43
- XML::DocumentFragment.parse(string, options, &block)
30
+ # Convenience method for Nokogiri::XML::DocumentFragment.parse
31
+ def fragment(...)
32
+ XML::DocumentFragment.parse(...)
44
33
  end
45
34
  end
46
35
  end
data/lib/nokogiri/xslt.rb CHANGED
@@ -3,15 +3,9 @@
3
3
 
4
4
  module Nokogiri
5
5
  class << self
6
- ###
7
- # Create a Nokogiri::XSLT::Stylesheet with +stylesheet+.
8
- #
9
- # Example:
10
- #
11
- # xslt = Nokogiri::XSLT(File.read(ARGV[0]))
12
- #
13
- def XSLT(stylesheet, modules = {})
14
- XSLT.parse(stylesheet, modules)
6
+ # Convenience method for Nokogiri::XSLT.parse
7
+ def XSLT(...)
8
+ XSLT.parse(...)
15
9
  end
16
10
  end
17
11
 
@@ -7,10 +7,9 @@ module XSD
7
7
  ###
8
8
  # Nokogiri XML parser for soap4r.
9
9
  #
10
- # Nokogiri may be used as the XML parser in soap4r. Simply require
11
- # 'xsd/xmlparser/nokogiri' in your soap4r applications, and soap4r
12
- # will use Nokogiri as it's XML parser. No other changes should be
13
- # required to use Nokogiri as the XML parser.
10
+ # Nokogiri may be used as the XML parser in soap4r. Require 'xsd/xmlparser/nokogiri' in your
11
+ # soap4r applications, and soap4r will use Nokogiri as its XML parser. No other changes should
12
+ # be required to use Nokogiri as the XML parser.
14
13
  #
15
14
  # Example (using UW ITS Web Services):
16
15
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.8
4
+ version: 1.17.0
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Mike Dalessio
@@ -20,7 +20,7 @@ authors:
20
20
  autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
- date: 2024-12-02 00:00:00.000000000 Z
23
+ date: 2024-12-08 00:00:00.000000000 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: racc
@@ -49,9 +49,10 @@ extra_rdoc_files:
49
49
  - ext/nokogiri/html4_document.c
50
50
  - ext/nokogiri/html4_element_description.c
51
51
  - ext/nokogiri/html4_entity_lookup.c
52
+ - ext/nokogiri/html4_sax_parser.c
52
53
  - ext/nokogiri/html4_sax_parser_context.c
53
54
  - ext/nokogiri/html4_sax_push_parser.c
54
- - ext/nokogiri/libxml2_backwards_compat.c
55
+ - ext/nokogiri/libxml2_polyfill.c
55
56
  - ext/nokogiri/nokogiri.c
56
57
  - ext/nokogiri/test_global_handlers.c
57
58
  - ext/nokogiri/xml_attr.c
@@ -94,6 +95,7 @@ files:
94
95
  - ext/nokogiri/html4_document.c
95
96
  - ext/nokogiri/html4_element_description.c
96
97
  - ext/nokogiri/html4_entity_lookup.c
98
+ - ext/nokogiri/html4_sax_parser.c
97
99
  - ext/nokogiri/html4_sax_parser_context.c
98
100
  - ext/nokogiri/html4_sax_push_parser.c
99
101
  - ext/nokogiri/include/libexslt/exslt.h
@@ -166,7 +168,7 @@ files:
166
168
  - ext/nokogiri/include/libxslt/xsltexports.h
167
169
  - ext/nokogiri/include/libxslt/xsltlocale.h
168
170
  - ext/nokogiri/include/libxslt/xsltutils.h
169
- - ext/nokogiri/libxml2_backwards_compat.c
171
+ - ext/nokogiri/libxml2_polyfill.c
170
172
  - ext/nokogiri/nokogiri.c
171
173
  - ext/nokogiri/nokogiri.h
172
174
  - ext/nokogiri/test_global_handlers.c
@@ -210,6 +212,7 @@ files:
210
212
  - lib/nokogiri/css/parser.rb
211
213
  - lib/nokogiri/css/parser.y
212
214
  - lib/nokogiri/css/parser_extras.rb
215
+ - lib/nokogiri/css/selector_cache.rb
213
216
  - lib/nokogiri/css/syntax_error.rb
214
217
  - lib/nokogiri/css/tokenizer.rb
215
218
  - lib/nokogiri/css/tokenizer.rex
@@ -231,6 +234,7 @@ files:
231
234
  - lib/nokogiri/html4/sax/parser_context.rb
232
235
  - lib/nokogiri/html4/sax/push_parser.rb
233
236
  - lib/nokogiri/html5.rb
237
+ - lib/nokogiri/html5/builder.rb
234
238
  - lib/nokogiri/html5/document.rb
235
239
  - lib/nokogiri/html5/document_fragment.rb
236
240
  - lib/nokogiri/html5/node.rb