nokogiri 1.12.4-java → 1.13.2-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +9 -7
  4. data/bin/nokogiri +63 -50
  5. data/dependencies.yml +11 -62
  6. data/ext/java/nokogiri/Html4SaxPushParser.java +14 -19
  7. data/ext/java/nokogiri/XmlDocumentFragment.java +4 -3
  8. data/ext/java/nokogiri/XmlNamespace.java +0 -8
  9. data/ext/java/nokogiri/XmlNode.java +23 -2
  10. data/ext/java/nokogiri/XmlNodeSet.java +0 -4
  11. data/ext/java/nokogiri/XmlReader.java +12 -0
  12. data/ext/java/nokogiri/XmlSaxParserContext.java +31 -93
  13. data/ext/java/nokogiri/XmlSaxPushParser.java +17 -25
  14. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +1 -1
  15. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +29 -8
  16. data/ext/java/nokogiri/internals/NokogiriHandler.java +6 -24
  17. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +9 -8
  18. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +10 -9
  19. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +7 -6
  20. data/ext/java/nokogiri/internals/SaveContextVisitor.java +2 -0
  21. data/ext/java/nokogiri/internals/XmlDomParserContext.java +16 -25
  22. data/ext/nokogiri/extconf.rb +64 -37
  23. data/ext/nokogiri/xml_document.c +35 -35
  24. data/ext/nokogiri/xml_document_fragment.c +0 -2
  25. data/ext/nokogiri/xml_dtd.c +2 -2
  26. data/ext/nokogiri/xml_encoding_handler.c +25 -11
  27. data/ext/nokogiri/xml_node.c +638 -333
  28. data/ext/nokogiri/xml_reader.c +37 -11
  29. data/ext/nokogiri/xml_xpath_context.c +72 -49
  30. data/ext/nokogiri/xslt_stylesheet.c +107 -9
  31. data/lib/nokogiri/class_resolver.rb +67 -0
  32. data/lib/nokogiri/css/node.rb +9 -8
  33. data/lib/nokogiri/css/parser.rb +360 -341
  34. data/lib/nokogiri/css/parser.y +249 -244
  35. data/lib/nokogiri/css/parser_extras.rb +20 -20
  36. data/lib/nokogiri/css/syntax_error.rb +1 -0
  37. data/lib/nokogiri/css/tokenizer.rb +4 -3
  38. data/lib/nokogiri/css/tokenizer.rex +3 -2
  39. data/lib/nokogiri/css/xpath_visitor.rb +179 -82
  40. data/lib/nokogiri/css.rb +38 -6
  41. data/lib/nokogiri/decorators/slop.rb +8 -7
  42. data/lib/nokogiri/extension.rb +1 -1
  43. data/lib/nokogiri/gumbo.rb +1 -0
  44. data/lib/nokogiri/html.rb +16 -10
  45. data/lib/nokogiri/html4/builder.rb +1 -0
  46. data/lib/nokogiri/html4/document.rb +84 -75
  47. data/lib/nokogiri/html4/document_fragment.rb +11 -7
  48. data/lib/nokogiri/html4/element_description.rb +1 -0
  49. data/lib/nokogiri/html4/element_description_defaults.rb +426 -520
  50. data/lib/nokogiri/html4/entity_lookup.rb +2 -1
  51. data/lib/nokogiri/html4/sax/parser.rb +2 -1
  52. data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
  53. data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
  54. data/lib/nokogiri/html4.rb +11 -5
  55. data/lib/nokogiri/html5/document.rb +24 -10
  56. data/lib/nokogiri/html5/document_fragment.rb +5 -2
  57. data/lib/nokogiri/html5/node.rb +6 -3
  58. data/lib/nokogiri/html5.rb +68 -64
  59. data/lib/nokogiri/jruby/dependencies.rb +10 -9
  60. data/lib/nokogiri/nokogiri.jar +0 -0
  61. data/lib/nokogiri/syntax_error.rb +1 -0
  62. data/lib/nokogiri/version/constant.rb +2 -1
  63. data/lib/nokogiri/version/info.rb +19 -13
  64. data/lib/nokogiri/version.rb +1 -0
  65. data/lib/nokogiri/xml/attr.rb +5 -3
  66. data/lib/nokogiri/xml/attribute_decl.rb +2 -1
  67. data/lib/nokogiri/xml/builder.rb +32 -32
  68. data/lib/nokogiri/xml/cdata.rb +2 -1
  69. data/lib/nokogiri/xml/character_data.rb +1 -0
  70. data/lib/nokogiri/xml/document.rb +139 -103
  71. data/lib/nokogiri/xml/document_fragment.rb +41 -38
  72. data/lib/nokogiri/xml/dtd.rb +3 -2
  73. data/lib/nokogiri/xml/element_content.rb +1 -0
  74. data/lib/nokogiri/xml/element_decl.rb +2 -1
  75. data/lib/nokogiri/xml/entity_decl.rb +3 -2
  76. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  77. data/lib/nokogiri/xml/namespace.rb +2 -0
  78. data/lib/nokogiri/xml/node/save_options.rb +7 -4
  79. data/lib/nokogiri/xml/node.rb +512 -348
  80. data/lib/nokogiri/xml/node_set.rb +46 -54
  81. data/lib/nokogiri/xml/notation.rb +12 -0
  82. data/lib/nokogiri/xml/parse_options.rb +11 -7
  83. data/lib/nokogiri/xml/pp/character_data.rb +8 -6
  84. data/lib/nokogiri/xml/pp/node.rb +24 -26
  85. data/lib/nokogiri/xml/pp.rb +1 -0
  86. data/lib/nokogiri/xml/processing_instruction.rb +2 -1
  87. data/lib/nokogiri/xml/reader.rb +17 -19
  88. data/lib/nokogiri/xml/relax_ng.rb +1 -0
  89. data/lib/nokogiri/xml/sax/document.rb +20 -19
  90. data/lib/nokogiri/xml/sax/parser.rb +36 -34
  91. data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
  92. data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
  93. data/lib/nokogiri/xml/sax.rb +1 -0
  94. data/lib/nokogiri/xml/schema.rb +7 -6
  95. data/lib/nokogiri/xml/searchable.rb +93 -62
  96. data/lib/nokogiri/xml/syntax_error.rb +4 -4
  97. data/lib/nokogiri/xml/text.rb +1 -0
  98. data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
  99. data/lib/nokogiri/xml/xpath.rb +12 -0
  100. data/lib/nokogiri/xml/xpath_context.rb +2 -3
  101. data/lib/nokogiri/xml.rb +3 -3
  102. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  103. data/lib/nokogiri/xslt.rb +21 -13
  104. data/lib/nokogiri.rb +19 -16
  105. data/lib/xsd/xmlparser/nokogiri.rb +25 -24
  106. metadata +102 -30
@@ -1,28 +1,39 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class DocumentFragment < Nokogiri::XML::Node
6
+ ####
7
+ # Create a Nokogiri::XML::DocumentFragment from +tags+
8
+ def self.parse(tags, options = ParseOptions::DEFAULT_XML, &block)
9
+ new(XML::Document.new, tags, nil, options, &block)
10
+ end
11
+
5
12
  ##
6
13
  # Create a new DocumentFragment from +tags+.
7
14
  #
8
15
  # If +ctx+ is present, it is used as a context node for the
9
16
  # subtree created, e.g., namespaces will be resolved relative
10
17
  # to +ctx+.
11
- def initialize document, tags = nil, ctx = nil
18
+ def initialize(document, tags = nil, ctx = nil, options = ParseOptions::DEFAULT_XML)
12
19
  return self unless tags
13
20
 
21
+ options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
22
+ yield options if block_given?
23
+
14
24
  children = if ctx
15
- # Fix for issue#490
16
- if Nokogiri.jruby?
17
- # fix for issue #770
18
- ctx.parse("<root #{namespace_declarations(ctx)}>#{tags}</root>").children
19
- else
20
- ctx.parse(tags)
21
- end
22
- else
23
- XML::Document.parse("<root>#{tags}</root>") \
24
- .xpath("/root/node()")
25
- end
25
+ # Fix for issue#490
26
+ if Nokogiri.jruby?
27
+ # fix for issue #770
28
+ ctx.parse("<root #{namespace_declarations(ctx)}>#{tags}</root>", options).children
29
+ else
30
+ ctx.parse(tags, options)
31
+ end
32
+ else
33
+ wrapper_doc = XML::Document.parse("<root>#{tags}</root>", nil, nil, options)
34
+ self.errors = wrapper_doc.errors
35
+ wrapper_doc.xpath("/root/node()")
36
+ end
26
37
  children.each { |child| child.parent = self }
27
38
  end
28
39
 
@@ -40,7 +51,7 @@ module Nokogiri
40
51
  ###
41
52
  # return the name for DocumentFragment
42
53
  def name
43
- '#document-fragment'
54
+ "#document-fragment"
44
55
  end
45
56
 
46
57
  ###
@@ -52,10 +63,10 @@ module Nokogiri
52
63
  ###
53
64
  # Convert this DocumentFragment to html
54
65
  # See Nokogiri::XML::NodeSet#to_html
55
- def to_html *args
66
+ def to_html(*args)
56
67
  if Nokogiri.jruby?
57
68
  options = args.first.is_a?(Hash) ? args.shift : {}
58
- if !options[:save_with]
69
+ unless options[:save_with]
59
70
  options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
60
71
  end
61
72
  args.insert(0, options)
@@ -66,10 +77,10 @@ module Nokogiri
66
77
  ###
67
78
  # Convert this DocumentFragment to xhtml
68
79
  # See Nokogiri::XML::NodeSet#to_xhtml
69
- def to_xhtml *args
80
+ def to_xhtml(*args)
70
81
  if Nokogiri.jruby?
71
82
  options = args.first.is_a?(Hash) ? args.shift : {}
72
- if !options[:save_with]
83
+ unless options[:save_with]
73
84
  options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_XHTML
74
85
  end
75
86
  args.insert(0, options)
@@ -80,7 +91,7 @@ module Nokogiri
80
91
  ###
81
92
  # Convert this DocumentFragment to xml
82
93
  # See Nokogiri::XML::NodeSet#to_xml
83
- def to_xml *args
94
+ def to_xml(*args)
84
95
  children.to_xml(*args)
85
96
  end
86
97
 
@@ -91,7 +102,7 @@ module Nokogiri
91
102
  # selectors. For example:
92
103
  #
93
104
  # For more information see Nokogiri::XML::Searchable#css
94
- def css *args
105
+ def css(*args)
95
106
  if children.any?
96
107
  children.css(*args) # 'children' is a smell here
97
108
  else
@@ -110,34 +121,26 @@ module Nokogiri
110
121
  # Search this fragment for +paths+. +paths+ must be one or more XPath or CSS queries.
111
122
  #
112
123
  # For more information see Nokogiri::XML::Searchable#search
113
- def search *rules
124
+ def search(*rules)
114
125
  rules, handler, ns, binds = extract_params(rules)
115
126
 
116
127
  rules.inject(NodeSet.new(document)) do |set, rule|
117
- set += if rule =~ Searchable::LOOKS_LIKE_XPATH
118
- xpath(*([rule, ns, handler, binds].compact))
119
- else
120
- children.css(*([rule, ns, handler].compact)) # 'children' is a smell here
121
- end
128
+ set + if Searchable::LOOKS_LIKE_XPATH.match?(rule)
129
+ xpath(*[rule, ns, handler, binds].compact)
130
+ else
131
+ children.css(*[rule, ns, handler].compact) # 'children' is a smell here
132
+ end
122
133
  end
123
134
  end
124
135
 
125
- alias :serialize :to_s
126
-
127
- class << self
128
- ####
129
- # Create a Nokogiri::XML::DocumentFragment from +tags+
130
- def parse tags
131
- self.new(XML::Document.new, tags)
132
- end
133
- end
136
+ alias_method :serialize, :to_s
134
137
 
135
138
  # A list of Nokogiri::XML::SyntaxError found when parsing a document
136
139
  def errors
137
140
  document.errors
138
141
  end
139
142
 
140
- def errors= things # :nodoc:
143
+ def errors=(things) # :nodoc:
141
144
  document.errors = things
142
145
  end
143
146
 
@@ -148,11 +151,11 @@ module Nokogiri
148
151
  private
149
152
 
150
153
  # fix for issue 770
151
- def namespace_declarations ctx
154
+ def namespace_declarations(ctx)
152
155
  ctx.namespace_scopes.map do |namespace|
153
156
  prefix = namespace.prefix.nil? ? "" : ":#{namespace.prefix}"
154
- %Q{xmlns#{prefix}="#{namespace.href}"}
155
- end.join ' '
157
+ %{xmlns#{prefix}="#{namespace.href}"}
158
+ end.join(" ")
156
159
  end
157
160
  end
158
161
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class DTD < Nokogiri::XML::Node
@@ -20,13 +21,13 @@ module Nokogiri
20
21
  end
21
22
 
22
23
  def html_dtd?
23
- name.casecmp('html').zero?
24
+ name.casecmp("html").zero?
24
25
  end
25
26
 
26
27
  def html5_dtd?
27
28
  html_dtd? &&
28
29
  external_id.nil? &&
29
- (system_id.nil? || system_id == 'about:legacy-compat')
30
+ (system_id.nil? || system_id == "about:legacy-compat")
30
31
  end
31
32
  end
32
33
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  ###
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class ElementDecl < Nokogiri::XML::Node
@@ -7,7 +8,7 @@ module Nokogiri
7
8
  undef_method :line if method_defined?(:line)
8
9
 
9
10
  def inspect
10
- "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{to_s.inspect}>"
11
+ "#<#{self.class.name}:#{format("0x%x", object_id)} #{to_s.inspect}>"
11
12
  end
12
13
  end
13
14
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class EntityDecl < Nokogiri::XML::Node
@@ -8,12 +9,12 @@ module Nokogiri
8
9
  undef_method :namespace_definitions
9
10
  undef_method :line if method_defined?(:line)
10
11
 
11
- def self.new name, doc, *args
12
+ def self.new(name, doc, *args)
12
13
  doc.create_entity(name, *args)
13
14
  end
14
15
 
15
16
  def inspect
16
- "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{to_s.inspect}>"
17
+ "#<#{self.class.name}:#{format("0x%x", object_id)} #{to_s.inspect}>"
17
18
  end
18
19
  end
19
20
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class EntityReference < Nokogiri::XML::Node
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class Namespace
@@ -6,6 +7,7 @@ module Nokogiri
6
7
  attr_reader :document
7
8
 
8
9
  private
10
+
9
11
  def inspect_attributes
10
12
  [:prefix, :href]
11
13
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class Node
@@ -22,7 +23,7 @@ module Nokogiri
22
23
 
23
24
  if Nokogiri.jruby?
24
25
  # Save builder created document
25
- AS_BUILDER = 128
26
+ AS_BUILDER = 128
26
27
  # the default for XML documents
27
28
  DEFAULT_XML = AS_XML # https://github.com/sparklemotion/nokogiri/issues/#issue/415
28
29
  # the default for HTML document
@@ -34,13 +35,15 @@ module Nokogiri
34
35
  DEFAULT_HTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
35
36
  end
36
37
  # the default for XHTML document
37
- DEFAULT_XHTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_XHTML
38
+ DEFAULT_XHTML = FORMAT | NO_DECLARATION | AS_XHTML
38
39
 
39
40
  # Integer representation of the SaveOptions
40
41
  attr_reader :options
41
42
 
42
43
  # Create a new SaveOptions object with +options+
43
- def initialize options = 0; @options = options; end
44
+ def initialize(options = 0)
45
+ @options = options
46
+ end
44
47
 
45
48
  constants.each do |constant|
46
49
  class_eval %{
@@ -55,7 +58,7 @@ module Nokogiri
55
58
  }
56
59
  end
57
60
 
58
- alias :to_i :options
61
+ alias_method :to_i, :options
59
62
  end
60
63
  end
61
64
  end