nokogiri 1.11.0.rc1-x86-linux

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 (145) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-DEPENDENCIES.md +1614 -0
  3. data/LICENSE.md +9 -0
  4. data/README.md +200 -0
  5. data/bin/nokogiri +118 -0
  6. data/dependencies.yml +74 -0
  7. data/ext/nokogiri/depend +358 -0
  8. data/ext/nokogiri/extconf.rb +695 -0
  9. data/ext/nokogiri/html_document.c +170 -0
  10. data/ext/nokogiri/html_document.h +10 -0
  11. data/ext/nokogiri/html_element_description.c +279 -0
  12. data/ext/nokogiri/html_element_description.h +10 -0
  13. data/ext/nokogiri/html_entity_lookup.c +32 -0
  14. data/ext/nokogiri/html_entity_lookup.h +8 -0
  15. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  16. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  17. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  18. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  19. data/ext/nokogiri/nokogiri.c +147 -0
  20. data/ext/nokogiri/nokogiri.h +122 -0
  21. data/ext/nokogiri/xml_attr.c +103 -0
  22. data/ext/nokogiri/xml_attr.h +9 -0
  23. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  24. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  25. data/ext/nokogiri/xml_cdata.c +62 -0
  26. data/ext/nokogiri/xml_cdata.h +9 -0
  27. data/ext/nokogiri/xml_comment.c +69 -0
  28. data/ext/nokogiri/xml_comment.h +9 -0
  29. data/ext/nokogiri/xml_document.c +617 -0
  30. data/ext/nokogiri/xml_document.h +23 -0
  31. data/ext/nokogiri/xml_document_fragment.c +48 -0
  32. data/ext/nokogiri/xml_document_fragment.h +10 -0
  33. data/ext/nokogiri/xml_dtd.c +202 -0
  34. data/ext/nokogiri/xml_dtd.h +10 -0
  35. data/ext/nokogiri/xml_element_content.c +123 -0
  36. data/ext/nokogiri/xml_element_content.h +10 -0
  37. data/ext/nokogiri/xml_element_decl.c +69 -0
  38. data/ext/nokogiri/xml_element_decl.h +9 -0
  39. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  40. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  41. data/ext/nokogiri/xml_entity_decl.c +110 -0
  42. data/ext/nokogiri/xml_entity_decl.h +10 -0
  43. data/ext/nokogiri/xml_entity_reference.c +52 -0
  44. data/ext/nokogiri/xml_entity_reference.h +9 -0
  45. data/ext/nokogiri/xml_io.c +61 -0
  46. data/ext/nokogiri/xml_io.h +11 -0
  47. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  48. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  49. data/ext/nokogiri/xml_namespace.c +111 -0
  50. data/ext/nokogiri/xml_namespace.h +14 -0
  51. data/ext/nokogiri/xml_node.c +1773 -0
  52. data/ext/nokogiri/xml_node.h +13 -0
  53. data/ext/nokogiri/xml_node_set.c +486 -0
  54. data/ext/nokogiri/xml_node_set.h +12 -0
  55. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  56. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  57. data/ext/nokogiri/xml_reader.c +668 -0
  58. data/ext/nokogiri/xml_reader.h +10 -0
  59. data/ext/nokogiri/xml_relax_ng.c +161 -0
  60. data/ext/nokogiri/xml_relax_ng.h +9 -0
  61. data/ext/nokogiri/xml_sax_parser.c +310 -0
  62. data/ext/nokogiri/xml_sax_parser.h +39 -0
  63. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  64. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  65. data/ext/nokogiri/xml_sax_push_parser.c +159 -0
  66. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  67. data/ext/nokogiri/xml_schema.c +205 -0
  68. data/ext/nokogiri/xml_schema.h +9 -0
  69. data/ext/nokogiri/xml_syntax_error.c +64 -0
  70. data/ext/nokogiri/xml_syntax_error.h +13 -0
  71. data/ext/nokogiri/xml_text.c +52 -0
  72. data/ext/nokogiri/xml_text.h +9 -0
  73. data/ext/nokogiri/xml_xpath_context.c +298 -0
  74. data/ext/nokogiri/xml_xpath_context.h +10 -0
  75. data/ext/nokogiri/xslt_stylesheet.c +266 -0
  76. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  77. data/lib/nokogiri.rb +127 -0
  78. data/lib/nokogiri/2.4/nokogiri.so +0 -0
  79. data/lib/nokogiri/2.5/nokogiri.so +0 -0
  80. data/lib/nokogiri/2.6/nokogiri.so +0 -0
  81. data/lib/nokogiri/2.7/nokogiri.so +0 -0
  82. data/lib/nokogiri/css.rb +28 -0
  83. data/lib/nokogiri/css/node.rb +53 -0
  84. data/lib/nokogiri/css/parser.rb +751 -0
  85. data/lib/nokogiri/css/parser.y +272 -0
  86. data/lib/nokogiri/css/parser_extras.rb +92 -0
  87. data/lib/nokogiri/css/syntax_error.rb +8 -0
  88. data/lib/nokogiri/css/tokenizer.rb +154 -0
  89. data/lib/nokogiri/css/tokenizer.rex +55 -0
  90. data/lib/nokogiri/css/xpath_visitor.rb +232 -0
  91. data/lib/nokogiri/decorators/slop.rb +43 -0
  92. data/lib/nokogiri/html.rb +38 -0
  93. data/lib/nokogiri/html/builder.rb +36 -0
  94. data/lib/nokogiri/html/document.rb +336 -0
  95. data/lib/nokogiri/html/document_fragment.rb +50 -0
  96. data/lib/nokogiri/html/element_description.rb +24 -0
  97. data/lib/nokogiri/html/element_description_defaults.rb +672 -0
  98. data/lib/nokogiri/html/entity_lookup.rb +14 -0
  99. data/lib/nokogiri/html/sax/parser.rb +63 -0
  100. data/lib/nokogiri/html/sax/parser_context.rb +17 -0
  101. data/lib/nokogiri/html/sax/push_parser.rb +37 -0
  102. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  103. data/lib/nokogiri/syntax_error.rb +5 -0
  104. data/lib/nokogiri/version.rb +149 -0
  105. data/lib/nokogiri/xml.rb +76 -0
  106. data/lib/nokogiri/xml/attr.rb +15 -0
  107. data/lib/nokogiri/xml/attribute_decl.rb +19 -0
  108. data/lib/nokogiri/xml/builder.rb +447 -0
  109. data/lib/nokogiri/xml/cdata.rb +12 -0
  110. data/lib/nokogiri/xml/character_data.rb +8 -0
  111. data/lib/nokogiri/xml/document.rb +280 -0
  112. data/lib/nokogiri/xml/document_fragment.rb +161 -0
  113. data/lib/nokogiri/xml/dtd.rb +33 -0
  114. data/lib/nokogiri/xml/element_content.rb +37 -0
  115. data/lib/nokogiri/xml/element_decl.rb +14 -0
  116. data/lib/nokogiri/xml/entity_decl.rb +20 -0
  117. data/lib/nokogiri/xml/entity_reference.rb +19 -0
  118. data/lib/nokogiri/xml/namespace.rb +14 -0
  119. data/lib/nokogiri/xml/node.rb +916 -0
  120. data/lib/nokogiri/xml/node/save_options.rb +62 -0
  121. data/lib/nokogiri/xml/node_set.rb +372 -0
  122. data/lib/nokogiri/xml/notation.rb +7 -0
  123. data/lib/nokogiri/xml/parse_options.rb +121 -0
  124. data/lib/nokogiri/xml/pp.rb +3 -0
  125. data/lib/nokogiri/xml/pp/character_data.rb +19 -0
  126. data/lib/nokogiri/xml/pp/node.rb +57 -0
  127. data/lib/nokogiri/xml/processing_instruction.rb +9 -0
  128. data/lib/nokogiri/xml/reader.rb +116 -0
  129. data/lib/nokogiri/xml/relax_ng.rb +33 -0
  130. data/lib/nokogiri/xml/sax.rb +5 -0
  131. data/lib/nokogiri/xml/sax/document.rb +172 -0
  132. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  133. data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
  134. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  135. data/lib/nokogiri/xml/schema.rb +64 -0
  136. data/lib/nokogiri/xml/searchable.rb +231 -0
  137. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  138. data/lib/nokogiri/xml/text.rb +10 -0
  139. data/lib/nokogiri/xml/xpath.rb +11 -0
  140. data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
  141. data/lib/nokogiri/xml/xpath_context.rb +17 -0
  142. data/lib/nokogiri/xslt.rb +57 -0
  143. data/lib/nokogiri/xslt/stylesheet.rb +26 -0
  144. data/lib/xsd/xmlparser/nokogiri.rb +103 -0
  145. metadata +482 -0
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ module SAX
5
+ ###
6
+ # Context for XML SAX parsers. This class is usually not instantiated
7
+ # by the user. Instead, you should be looking at
8
+ # Nokogiri::XML::SAX::Parser
9
+ class ParserContext
10
+ def self.new thing, encoding = 'UTF-8'
11
+ [:read, :close].all? { |x| thing.respond_to?(x) } ?
12
+ io(thing, Parser::ENCODINGS[encoding]) : memory(thing)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ module SAX
5
+ ###
6
+ # PushParser can parse a document that is fed to it manually. It
7
+ # must be given a SAX::Document object which will be called with
8
+ # SAX events as the document is being parsed.
9
+ #
10
+ # Calling PushParser#<< writes XML to the parser, calling any SAX
11
+ # callbacks it can.
12
+ #
13
+ # PushParser#finish tells the parser that the document is finished
14
+ # and calls the end_document SAX method.
15
+ #
16
+ # Example:
17
+ #
18
+ # parser = PushParser.new(Class.new(XML::SAX::Document) {
19
+ # def start_document
20
+ # puts "start document called"
21
+ # end
22
+ # }.new)
23
+ # parser << "<div>hello<"
24
+ # parser << "/div>"
25
+ # parser.finish
26
+ class PushParser
27
+
28
+ # The Nokogiri::XML::SAX::Document on which the PushParser will be
29
+ # operating
30
+ attr_accessor :document
31
+
32
+ ###
33
+ # Create a new PushParser with +doc+ as the SAX Document, providing
34
+ # an optional +file_name+ and +encoding+
35
+ def initialize(doc = XML::SAX::Document.new, file_name = nil, encoding = 'UTF-8')
36
+ @document = doc
37
+ @encoding = encoding
38
+ @sax_parser = XML::SAX::Parser.new(doc)
39
+
40
+ ## Create our push parser context
41
+ initialize_native(@sax_parser, file_name)
42
+ end
43
+
44
+ ###
45
+ # Write a +chunk+ of XML to the PushParser. Any callback methods
46
+ # that can be called will be called immediately.
47
+ def write chunk, last_chunk = false
48
+ native_write(chunk, last_chunk)
49
+ end
50
+ alias :<< :write
51
+
52
+ ###
53
+ # Finish the parsing. This method is only necessary for
54
+ # Nokogiri::XML::SAX::Document#end_document to be called.
55
+ def finish
56
+ write '', true
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ class << self
5
+ ###
6
+ # Create a new Nokogiri::XML::Schema object using a +string_or_io+
7
+ # object.
8
+ def Schema string_or_io
9
+ Schema.new(string_or_io)
10
+ end
11
+ end
12
+
13
+ ###
14
+ # Nokogiri::XML::Schema is used for validating XML against a schema
15
+ # (usually from an xsd file).
16
+ #
17
+ # == Synopsis
18
+ #
19
+ # Validate an XML document against a Schema. Loop over the errors that
20
+ # are returned and print them out:
21
+ #
22
+ # xsd = Nokogiri::XML::Schema(File.read(PO_SCHEMA_FILE))
23
+ # doc = Nokogiri::XML(File.read(PO_XML_FILE))
24
+ #
25
+ # xsd.validate(doc).each do |error|
26
+ # puts error.message
27
+ # end
28
+ #
29
+ # The list of errors are Nokogiri::XML::SyntaxError objects.
30
+ class Schema
31
+ # Errors while parsing the schema file
32
+ attr_accessor :errors
33
+
34
+ ###
35
+ # Create a new Nokogiri::XML::Schema object using a +string_or_io+
36
+ # object.
37
+ def self.new string_or_io
38
+ from_document Nokogiri::XML(string_or_io)
39
+ end
40
+
41
+ ###
42
+ # Validate +thing+ against this schema. +thing+ can be a
43
+ # Nokogiri::XML::Document object, or a filename. An Array of
44
+ # Nokogiri::XML::SyntaxError objects found while validating the
45
+ # +thing+ is returned.
46
+ def validate thing
47
+ if thing.is_a?(Nokogiri::XML::Document)
48
+ validate_document(thing)
49
+ elsif File.file?(thing)
50
+ validate_file(thing)
51
+ else
52
+ raise ArgumentError, "Must provide Nokogiri::Xml::Document or the name of an existing file"
53
+ end
54
+ end
55
+
56
+ ###
57
+ # Returns true if +thing+ is a valid Nokogiri::XML::Document or
58
+ # file.
59
+ def valid? thing
60
+ validate(thing).length == 0
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,231 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ #
5
+ # The Searchable module declares the interface used for searching your DOM.
6
+ #
7
+ # It implements the public methods `search`, `css`, and `xpath`,
8
+ # as well as allowing specific implementations to specialize some
9
+ # of the important behaviors.
10
+ #
11
+ module Searchable
12
+ # Regular expression used by Searchable#search to determine if a query
13
+ # string is CSS or XPath
14
+ LOOKS_LIKE_XPATH = /^(\.\/|\/|\.\.|\.$)/
15
+
16
+ ###
17
+ # call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
18
+ #
19
+ # Search this object for +paths+. +paths+ must be one or more XPath or CSS queries:
20
+ #
21
+ # node.search("div.employee", ".//title")
22
+ #
23
+ # A hash of namespace bindings may be appended:
24
+ #
25
+ # node.search('.//bike:tire', {'bike' => 'http://schwinn.com/'})
26
+ # node.search('bike|tire', {'bike' => 'http://schwinn.com/'})
27
+ #
28
+ # For XPath queries, a hash of variable bindings may also be
29
+ # appended to the namespace bindings. For example:
30
+ #
31
+ # node.search('.//address[@domestic=$value]', nil, {:value => 'Yes'})
32
+ #
33
+ # Custom XPath functions and CSS pseudo-selectors may also be
34
+ # defined. To define custom functions create a class and
35
+ # implement the function you want to define. The first argument
36
+ # to the method will be the current matching NodeSet. Any other
37
+ # arguments are ones that you pass in. Note that this class may
38
+ # appear anywhere in the argument list. For example:
39
+ #
40
+ # node.search('.//title[regex(., "\w+")]', 'div.employee:regex("[0-9]+")'
41
+ # Class.new {
42
+ # def regex node_set, regex
43
+ # node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
44
+ # end
45
+ # }.new
46
+ # )
47
+ #
48
+ # See Searchable#xpath and Searchable#css for further usage help.
49
+ def search *args
50
+ paths, handler, ns, binds = extract_params(args)
51
+
52
+ xpaths = paths.map(&:to_s).map do |path|
53
+ (path =~ LOOKS_LIKE_XPATH) ? path : xpath_query_from_css_rule(path, ns)
54
+ end.flatten.uniq
55
+
56
+ xpath(*(xpaths + [ns, handler, binds].compact))
57
+ end
58
+ alias :/ :search
59
+
60
+ ###
61
+ # call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
62
+ #
63
+ # Search this object for +paths+, and return only the first
64
+ # result. +paths+ must be one or more XPath or CSS queries.
65
+ #
66
+ # See Searchable#search for more information.
67
+ def at *args
68
+ search(*args).first
69
+ end
70
+ alias :% :at
71
+
72
+ ###
73
+ # call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
74
+ #
75
+ # Search this object for CSS +rules+. +rules+ must be one or more CSS
76
+ # selectors. For example:
77
+ #
78
+ # node.css('title')
79
+ # node.css('body h1.bold')
80
+ # node.css('div + p.green', 'div#one')
81
+ #
82
+ # A hash of namespace bindings may be appended. For example:
83
+ #
84
+ # node.css('bike|tire', {'bike' => 'http://schwinn.com/'})
85
+ #
86
+ # Custom CSS pseudo classes may also be defined. To define
87
+ # custom pseudo classes, create a class and implement the custom
88
+ # pseudo class you want defined. The first argument to the
89
+ # method will be the current matching NodeSet. Any other
90
+ # arguments are ones that you pass in. For example:
91
+ #
92
+ # node.css('title:regex("\w+")', Class.new {
93
+ # def regex node_set, regex
94
+ # node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
95
+ # end
96
+ # }.new)
97
+ #
98
+ # Note that the CSS query string is case-sensitive with regards
99
+ # to your document type. That is, if you're looking for "H1" in
100
+ # an HTML document, you'll never find anything, since HTML tags
101
+ # will match only lowercase CSS queries. However, "H1" might be
102
+ # found in an XML document, where tags names are case-sensitive
103
+ # (e.g., "H1" is distinct from "h1").
104
+ #
105
+ def css *args
106
+ rules, handler, ns, _ = extract_params(args)
107
+
108
+ css_internal self, rules, handler, ns
109
+ end
110
+
111
+ ##
112
+ # call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
113
+ #
114
+ # Search this object for CSS +rules+, and return only the first
115
+ # match. +rules+ must be one or more CSS selectors.
116
+ #
117
+ # See Searchable#css for more information.
118
+ def at_css *args
119
+ css(*args).first
120
+ end
121
+
122
+ ###
123
+ # call-seq: xpath *paths, [namespace-bindings, variable-bindings, custom-handler-class]
124
+ #
125
+ # Search this node for XPath +paths+. +paths+ must be one or more XPath
126
+ # queries.
127
+ #
128
+ # node.xpath('.//title')
129
+ #
130
+ # A hash of namespace bindings may be appended. For example:
131
+ #
132
+ # node.xpath('.//foo:name', {'foo' => 'http://example.org/'})
133
+ # node.xpath('.//xmlns:name', node.root.namespaces)
134
+ #
135
+ # A hash of variable bindings may also be appended to the namespace bindings. For example:
136
+ #
137
+ # node.xpath('.//address[@domestic=$value]', nil, {:value => 'Yes'})
138
+ #
139
+ # Custom XPath functions may also be defined. To define custom
140
+ # functions create a class and implement the function you want
141
+ # to define. The first argument to the method will be the
142
+ # current matching NodeSet. Any other arguments are ones that
143
+ # you pass in. Note that this class may appear anywhere in the
144
+ # argument list. For example:
145
+ #
146
+ # node.xpath('.//title[regex(., "\w+")]', Class.new {
147
+ # def regex node_set, regex
148
+ # node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
149
+ # end
150
+ # }.new)
151
+ #
152
+ def xpath *args
153
+ paths, handler, ns, binds = extract_params(args)
154
+
155
+ xpath_internal self, paths, handler, ns, binds
156
+ end
157
+
158
+ ##
159
+ # call-seq: xpath *paths, [namespace-bindings, variable-bindings, custom-handler-class]
160
+ #
161
+ # Search this node for XPath +paths+, and return only the first
162
+ # match. +paths+ must be one or more XPath queries.
163
+ #
164
+ # See Searchable#xpath for more information.
165
+ def at_xpath *args
166
+ xpath(*args).first
167
+ end
168
+
169
+ private
170
+
171
+ def css_internal node, rules, handler, ns
172
+ xpath_internal node, css_rules_to_xpath(rules, ns), handler, ns, nil
173
+ end
174
+
175
+ def xpath_internal node, paths, handler, ns, binds
176
+ document = node.document
177
+ return NodeSet.new(document) unless document
178
+
179
+ if paths.length == 1
180
+ return xpath_impl(node, paths.first, handler, ns, binds)
181
+ end
182
+
183
+ NodeSet.new(document) do |combined|
184
+ paths.each do |path|
185
+ xpath_impl(node, path, handler, ns, binds).each { |set| combined << set }
186
+ end
187
+ end
188
+ end
189
+
190
+ def xpath_impl node, path, handler, ns, binds
191
+ ctx = XPathContext.new(node)
192
+ ctx.register_namespaces(ns)
193
+ path = path.gsub(/xmlns:/, ' :') unless Nokogiri.uses_libxml?
194
+
195
+ binds.each do |key,value|
196
+ ctx.register_variable key.to_s, value
197
+ end if binds
198
+
199
+ ctx.evaluate(path, handler)
200
+ end
201
+
202
+ def css_rules_to_xpath(rules, ns)
203
+ rules.map { |rule| xpath_query_from_css_rule(rule, ns) }
204
+ end
205
+
206
+ def xpath_query_from_css_rule rule, ns
207
+ self.class::IMPLIED_XPATH_CONTEXTS.map do |implied_xpath_context|
208
+ CSS.xpath_for(rule.to_s, :prefix => implied_xpath_context, :ns => ns)
209
+ end.join(' | ')
210
+ end
211
+
212
+ def extract_params params # :nodoc:
213
+ handler = params.find do |param|
214
+ ![Hash, String, Symbol].include?(param.class)
215
+ end
216
+ params -= [handler] if handler
217
+
218
+ hashes = []
219
+ while Hash === params.last || params.last.nil?
220
+ hashes << params.pop
221
+ break if params.empty?
222
+ end
223
+ ns, binds = hashes.reverse
224
+
225
+ ns ||= document.root ? document.root.namespaces : {}
226
+
227
+ [params, handler, ns, binds]
228
+ end
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ ###
5
+ # This class provides information about XML SyntaxErrors. These
6
+ # exceptions are typically stored on Nokogiri::XML::Document#errors.
7
+ class SyntaxError < ::Nokogiri::SyntaxError
8
+ attr_reader :domain
9
+ attr_reader :code
10
+ attr_reader :level
11
+ attr_reader :file
12
+ attr_reader :line
13
+ attr_reader :str1
14
+ attr_reader :str2
15
+ attr_reader :str3
16
+ attr_reader :int1
17
+ attr_reader :column
18
+
19
+ ###
20
+ # return true if this is a non error
21
+ def none?
22
+ level == 0
23
+ end
24
+
25
+ ###
26
+ # return true if this is a warning
27
+ def warning?
28
+ level == 1
29
+ end
30
+
31
+ ###
32
+ # return true if this is an error
33
+ def error?
34
+ level == 2
35
+ end
36
+
37
+ ###
38
+ # return true if this error is fatal
39
+ def fatal?
40
+ level == 3
41
+ end
42
+
43
+ def to_s
44
+ message = super.chomp
45
+ [location_to_s, level_to_s, message].
46
+ compact.join(": ").
47
+ force_encoding(message.encoding)
48
+ end
49
+
50
+ private
51
+
52
+ def level_to_s
53
+ case level
54
+ when 3 then "FATAL"
55
+ when 2 then "ERROR"
56
+ when 1 then "WARNING"
57
+ else nil
58
+ end
59
+ end
60
+
61
+ def nil_or_zero?(attribute)
62
+ attribute.nil? || attribute.zero?
63
+ end
64
+
65
+ def location_to_s
66
+ return nil if nil_or_zero?(line) && nil_or_zero?(column)
67
+ "#{line}:#{column}"
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ class Text < Nokogiri::XML::CharacterData
5
+ def content=(string)
6
+ self.native_content = string.to_s
7
+ end
8
+ end
9
+ end
10
+ end