nokogiri 1.10.3 → 1.11.4
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.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +1015 -947
- data/LICENSE.md +1 -1
- data/README.md +173 -94
- data/dependencies.yml +28 -26
- data/ext/nokogiri/depend +37 -358
- data/ext/nokogiri/extconf.rb +611 -391
- data/ext/nokogiri/html_document.c +78 -82
- data/ext/nokogiri/html_element_description.c +84 -71
- data/ext/nokogiri/html_entity_lookup.c +21 -16
- data/ext/nokogiri/html_sax_parser_context.c +69 -66
- data/ext/nokogiri/html_sax_push_parser.c +42 -34
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +192 -87
- data/ext/nokogiri/nokogiri.h +181 -89
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +15 -15
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +13 -18
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +255 -183
- data/ext/nokogiri/xml_document_fragment.c +13 -15
- data/ext/nokogiri/xml_dtd.c +54 -48
- data/ext/nokogiri/xml_element_content.c +30 -27
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +17 -11
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +56 -49
- data/ext/nokogiri/xml_node.c +387 -316
- data/ext/nokogiri/xml_node_set.c +168 -156
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +195 -172
- data/ext/nokogiri/xml_relax_ng.c +52 -28
- data/ext/nokogiri/xml_sax_parser.c +118 -118
- data/ext/nokogiri/xml_sax_parser_context.c +103 -86
- data/ext/nokogiri/xml_sax_push_parser.c +36 -27
- data/ext/nokogiri/xml_schema.c +111 -34
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +206 -123
- data/ext/nokogiri/xslt_stylesheet.c +158 -165
- data/lib/nokogiri/css/node.rb +1 -0
- data/lib/nokogiri/css/parser.rb +63 -62
- data/lib/nokogiri/css/parser.y +2 -2
- data/lib/nokogiri/css/parser_extras.rb +39 -36
- data/lib/nokogiri/css/syntax_error.rb +1 -0
- data/lib/nokogiri/css/tokenizer.rb +105 -103
- data/lib/nokogiri/css/xpath_visitor.rb +73 -43
- data/lib/nokogiri/css.rb +1 -0
- data/lib/nokogiri/decorators/slop.rb +1 -0
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/builder.rb +1 -0
- data/lib/nokogiri/html/document.rb +13 -26
- data/lib/nokogiri/html/document_fragment.rb +16 -15
- data/lib/nokogiri/html/element_description.rb +1 -0
- data/lib/nokogiri/html/element_description_defaults.rb +1 -0
- data/lib/nokogiri/html/entity_lookup.rb +1 -0
- data/lib/nokogiri/html/sax/parser.rb +1 -0
- data/lib/nokogiri/html/sax/parser_context.rb +1 -0
- data/lib/nokogiri/html/sax/push_parser.rb +1 -0
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/jruby/dependencies.rb +20 -0
- data/lib/nokogiri/syntax_error.rb +1 -0
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +205 -0
- data/lib/nokogiri/version.rb +3 -109
- data/lib/nokogiri/xml/attr.rb +1 -0
- data/lib/nokogiri/xml/attribute_decl.rb +1 -0
- data/lib/nokogiri/xml/builder.rb +36 -32
- data/lib/nokogiri/xml/cdata.rb +1 -0
- data/lib/nokogiri/xml/character_data.rb +1 -0
- data/lib/nokogiri/xml/document.rb +92 -41
- data/lib/nokogiri/xml/document_fragment.rb +5 -6
- data/lib/nokogiri/xml/dtd.rb +1 -0
- data/lib/nokogiri/xml/element_content.rb +1 -0
- data/lib/nokogiri/xml/element_decl.rb +1 -0
- data/lib/nokogiri/xml/entity_decl.rb +1 -0
- data/lib/nokogiri/xml/entity_reference.rb +1 -0
- data/lib/nokogiri/xml/namespace.rb +1 -0
- data/lib/nokogiri/xml/node/save_options.rb +1 -0
- data/lib/nokogiri/xml/node.rb +625 -290
- data/lib/nokogiri/xml/node_set.rb +1 -0
- data/lib/nokogiri/xml/notation.rb +1 -0
- data/lib/nokogiri/xml/parse_options.rb +10 -3
- data/lib/nokogiri/xml/pp/character_data.rb +1 -0
- data/lib/nokogiri/xml/pp/node.rb +1 -0
- data/lib/nokogiri/xml/pp.rb +1 -0
- data/lib/nokogiri/xml/processing_instruction.rb +1 -0
- data/lib/nokogiri/xml/reader.rb +9 -12
- data/lib/nokogiri/xml/relax_ng.rb +7 -2
- data/lib/nokogiri/xml/sax/document.rb +1 -0
- data/lib/nokogiri/xml/sax/parser.rb +1 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +1 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +1 -0
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/schema.rb +13 -4
- data/lib/nokogiri/xml/searchable.rb +25 -16
- data/lib/nokogiri/xml/syntax_error.rb +1 -0
- data/lib/nokogiri/xml/text.rb +1 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
- data/lib/nokogiri/xml/xpath.rb +2 -3
- data/lib/nokogiri/xml/xpath_context.rb +1 -0
- data/lib/nokogiri/xml.rb +1 -0
- data/lib/nokogiri/xslt/stylesheet.rb +1 -0
- data/lib/nokogiri/xslt.rb +1 -0
- data/lib/nokogiri.rb +6 -27
- data/lib/xsd/xmlparser/nokogiri.rb +1 -0
- data/patches/libxml2/{0002-Remove-script-macro-support.patch → 0001-Remove-script-macro-support.patch} +0 -0
- data/patches/libxml2/{0003-Update-entities-to-remove-handling-of-ssi.patch → 0002-Update-entities-to-remove-handling-of-ssi.patch} +0 -0
- data/patches/libxml2/0003-libxml2.la-is-in-top_builddir.patch +25 -0
- data/patches/libxml2/0004-use-glibc-strlen.patch +53 -0
- data/patches/libxml2/0005-avoid-isnan-isinf.patch +81 -0
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +2511 -0
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2511 -0
- data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +19 -0
- data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
- metadata +102 -147
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.c +0 -61
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -14
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -13
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
- data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
- data/patches/libxslt/0001-Fix-security-framework-bypass.patch +0 -120
- data/ports/archives/libxml2-2.9.9.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.33.tar.gz +0 -0
@@ -1,28 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Nokogiri
|
2
3
|
module HTML
|
3
4
|
class DocumentFragment < Nokogiri::XML::DocumentFragment
|
4
5
|
####
|
5
6
|
# Create a Nokogiri::XML::DocumentFragment from +tags+, using +encoding+
|
6
|
-
def self.parse
|
7
|
+
def self.parse(tags, encoding = nil)
|
7
8
|
doc = HTML::Document.new
|
8
9
|
|
9
10
|
encoding ||= if tags.respond_to?(:encoding)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
encoding = tags.encoding
|
12
|
+
if encoding == ::Encoding::ASCII_8BIT
|
13
|
+
'UTF-8'
|
14
|
+
else
|
15
|
+
encoding.name
|
16
|
+
end
|
17
|
+
else
|
18
|
+
'UTF-8'
|
19
|
+
end
|
19
20
|
|
20
21
|
doc.encoding = encoding
|
21
22
|
|
22
23
|
new(doc, tags)
|
23
24
|
end
|
24
25
|
|
25
|
-
def initialize
|
26
|
+
def initialize(document, tags = nil, ctx = nil)
|
26
27
|
return self unless tags
|
27
28
|
|
28
29
|
if ctx
|
@@ -32,13 +33,13 @@ module Nokogiri
|
|
32
33
|
self.errors = document.errors - preexisting_errors
|
33
34
|
else
|
34
35
|
# This is a horrible hack, but I don't care
|
35
|
-
|
36
|
-
|
36
|
+
path = if /^\s*?<body/i.match?(tags)
|
37
|
+
"/html/body"
|
37
38
|
else
|
38
|
-
|
39
|
+
"/html/body/node()"
|
39
40
|
end
|
40
41
|
|
41
|
-
temp_doc = HTML::Document.parse
|
42
|
+
temp_doc = HTML::Document.parse("<html><body>#{tags}", nil, document.encoding)
|
42
43
|
temp_doc.xpath(path).each { |child| child.parent = self }
|
43
44
|
self.errors = temp_doc.errors
|
44
45
|
end
|
data/lib/nokogiri/html.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# The line below caused a problem on non-GAE rack environment.
|
3
|
+
# unless defined?(JRuby::Rack::VERSION) || defined?(AppEngine::ApiProxy)
|
4
|
+
#
|
5
|
+
# However, simply cutting defined?(JRuby::Rack::VERSION) off resulted in
|
6
|
+
# an unable-to-load-nokogiri problem. Thus, now, Nokogiri checks the presense
|
7
|
+
# of appengine-rack.jar in $LOAD_PATH. If Nokogiri is on GAE, Nokogiri
|
8
|
+
# should skip loading xml jars. This is because those are in WEB-INF/lib and
|
9
|
+
# already set in the classpath.
|
10
|
+
unless $LOAD_PATH.to_s.include?("appengine-rack")
|
11
|
+
require 'stringio'
|
12
|
+
require 'isorelax.jar'
|
13
|
+
require 'jing.jar'
|
14
|
+
require 'nekohtml.jar'
|
15
|
+
require 'nekodtd.jar'
|
16
|
+
require 'xercesImpl.jar'
|
17
|
+
require 'serializer.jar'
|
18
|
+
require 'xalan.jar'
|
19
|
+
require 'xml-apis.jar'
|
20
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "singleton"
|
3
|
+
require "shellwords"
|
4
|
+
|
5
|
+
module Nokogiri
|
6
|
+
class VersionInfo # :nodoc:
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def jruby?
|
10
|
+
::JRUBY_VERSION if ::RUBY_PLATFORM == "java"
|
11
|
+
end
|
12
|
+
|
13
|
+
def windows?
|
14
|
+
::RUBY_PLATFORM =~ /mingw|mswin/
|
15
|
+
end
|
16
|
+
|
17
|
+
def ruby_minor
|
18
|
+
Gem::Version.new(::RUBY_VERSION).segments[0..1].join(".")
|
19
|
+
end
|
20
|
+
|
21
|
+
def engine
|
22
|
+
defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : "mri"
|
23
|
+
end
|
24
|
+
|
25
|
+
def loaded_libxml_version
|
26
|
+
Gem::Version.new(Nokogiri::LIBXML_LOADED_VERSION
|
27
|
+
.scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first
|
28
|
+
.collect(&:to_i)
|
29
|
+
.join("."))
|
30
|
+
end
|
31
|
+
|
32
|
+
def compiled_libxml_version
|
33
|
+
Gem::Version.new(Nokogiri::LIBXML_COMPILED_VERSION)
|
34
|
+
end
|
35
|
+
|
36
|
+
def loaded_libxslt_version
|
37
|
+
Gem::Version.new(Nokogiri::LIBXSLT_LOADED_VERSION
|
38
|
+
.scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first
|
39
|
+
.collect(&:to_i)
|
40
|
+
.join("."))
|
41
|
+
end
|
42
|
+
|
43
|
+
def compiled_libxslt_version
|
44
|
+
Gem::Version.new(Nokogiri::LIBXSLT_COMPILED_VERSION)
|
45
|
+
end
|
46
|
+
|
47
|
+
def libxml2?
|
48
|
+
defined?(Nokogiri::LIBXML_COMPILED_VERSION)
|
49
|
+
end
|
50
|
+
|
51
|
+
def libxml2_has_iconv?
|
52
|
+
defined?(Nokogiri::LIBXML_ICONV_ENABLED) && Nokogiri::LIBXML_ICONV_ENABLED
|
53
|
+
end
|
54
|
+
|
55
|
+
def libxml2_using_packaged?
|
56
|
+
libxml2? && Nokogiri::PACKAGED_LIBRARIES
|
57
|
+
end
|
58
|
+
|
59
|
+
def libxml2_using_system?
|
60
|
+
libxml2? && !libxml2_using_packaged?
|
61
|
+
end
|
62
|
+
|
63
|
+
def libxml2_precompiled?
|
64
|
+
libxml2_using_packaged? && Nokogiri::PRECOMPILED_LIBRARIES
|
65
|
+
end
|
66
|
+
|
67
|
+
def warnings
|
68
|
+
warnings = []
|
69
|
+
|
70
|
+
if libxml2?
|
71
|
+
if compiled_libxml_version != loaded_libxml_version
|
72
|
+
warnings << "Nokogiri was built against libxml version #{compiled_libxml_version}, but has dynamically loaded #{loaded_libxml_version}"
|
73
|
+
end
|
74
|
+
|
75
|
+
if compiled_libxslt_version != loaded_libxslt_version
|
76
|
+
warnings << "Nokogiri was built against libxslt version #{compiled_libxslt_version}, but has dynamically loaded #{loaded_libxslt_version}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
warnings
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_hash
|
84
|
+
header_directory = File.expand_path(File.join(File.dirname(__FILE__), "../../../ext/nokogiri"))
|
85
|
+
|
86
|
+
{}.tap do |vi|
|
87
|
+
vi["warnings"] = []
|
88
|
+
vi["nokogiri"] = {}.tap do |nokogiri|
|
89
|
+
nokogiri["version"] = Nokogiri::VERSION
|
90
|
+
|
91
|
+
unless jruby?
|
92
|
+
# enable gems like nokogumbo to build with the following in their extconf.rb:
|
93
|
+
#
|
94
|
+
# append_cflags(Nokogiri::VERSION_INFO["nokogiri"]["cppflags"])
|
95
|
+
# append_ldflags(Nokogiri::VERSION_INFO["nokogiri"]["ldflags"])
|
96
|
+
#
|
97
|
+
cppflags = ["-I#{header_directory.shellescape}"]
|
98
|
+
ldflags = []
|
99
|
+
|
100
|
+
if libxml2_using_packaged?
|
101
|
+
cppflags << "-I#{File.join(header_directory, 'include').shellescape}"
|
102
|
+
cppflags << "-I#{File.join(header_directory, 'include/libxml2').shellescape}"
|
103
|
+
|
104
|
+
if windows?
|
105
|
+
# on windows, nokogumbo needs to link against nokogiri.so to resolve symbols. see #2167
|
106
|
+
lib_directory = File.expand_path(File.join(File.dirname(__FILE__), "../#{ruby_minor}"))
|
107
|
+
unless File.exist?(lib_directory)
|
108
|
+
lib_directory = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
109
|
+
end
|
110
|
+
ldflags << "-L#{lib_directory.shellescape}"
|
111
|
+
ldflags << "-l:nokogiri.so"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
nokogiri["cppflags"] = cppflags
|
116
|
+
nokogiri["ldflags"] = ldflags
|
117
|
+
end
|
118
|
+
end
|
119
|
+
vi["ruby"] = {}.tap do |ruby|
|
120
|
+
ruby["version"] = ::RUBY_VERSION
|
121
|
+
ruby["platform"] = ::RUBY_PLATFORM
|
122
|
+
ruby["gem_platform"] = ::Gem::Platform.local.to_s
|
123
|
+
ruby["description"] = ::RUBY_DESCRIPTION
|
124
|
+
ruby["engine"] = engine
|
125
|
+
ruby["jruby"] = jruby? if jruby?
|
126
|
+
end
|
127
|
+
|
128
|
+
if libxml2?
|
129
|
+
vi["libxml"] = {}.tap do |libxml|
|
130
|
+
if libxml2_using_packaged?
|
131
|
+
libxml["source"] = "packaged"
|
132
|
+
libxml["precompiled"] = libxml2_precompiled?
|
133
|
+
libxml["patches"] = Nokogiri::LIBXML2_PATCHES
|
134
|
+
|
135
|
+
# this is for nokogumbo and shouldn't be forever
|
136
|
+
libxml["libxml2_path"] = header_directory
|
137
|
+
else
|
138
|
+
libxml["source"] = "system"
|
139
|
+
end
|
140
|
+
libxml["iconv_enabled"] = libxml2_has_iconv?
|
141
|
+
libxml["compiled"] = compiled_libxml_version.to_s
|
142
|
+
libxml["loaded"] = loaded_libxml_version.to_s
|
143
|
+
end
|
144
|
+
|
145
|
+
vi["libxslt"] = {}.tap do |libxslt|
|
146
|
+
if libxml2_using_packaged?
|
147
|
+
libxslt["source"] = "packaged"
|
148
|
+
libxslt["precompiled"] = libxml2_precompiled?
|
149
|
+
libxslt["patches"] = Nokogiri::LIBXSLT_PATCHES
|
150
|
+
else
|
151
|
+
libxslt["source"] = "system"
|
152
|
+
end
|
153
|
+
libxslt["compiled"] = compiled_libxslt_version.to_s
|
154
|
+
libxslt["loaded"] = loaded_libxslt_version.to_s
|
155
|
+
end
|
156
|
+
|
157
|
+
vi["warnings"] = warnings
|
158
|
+
end
|
159
|
+
|
160
|
+
if defined?(Nokogiri::OTHER_LIBRARY_VERSIONS)
|
161
|
+
# see extconf for how this string is assembled: "lib1name:lib1version,lib2name:lib2version"
|
162
|
+
vi["other_libraries"] = Hash[*Nokogiri::OTHER_LIBRARY_VERSIONS.split(/[,:]/)]
|
163
|
+
elsif jruby?
|
164
|
+
vi["other_libraries"] = {}.tap do |ol|
|
165
|
+
ol["xerces"] = Nokogiri::XERCES_VERSION
|
166
|
+
ol["nekohtml"] = Nokogiri::NEKO_VERSION
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def to_markdown
|
173
|
+
begin
|
174
|
+
require "psych"
|
175
|
+
rescue LoadError
|
176
|
+
end
|
177
|
+
require "yaml"
|
178
|
+
"# Nokogiri (#{Nokogiri::VERSION})\n" +
|
179
|
+
YAML.dump(to_hash).each_line.map { |line| " #{line}" }.join
|
180
|
+
end
|
181
|
+
|
182
|
+
instance.warnings.each do |warning|
|
183
|
+
warn "WARNING: #{warning}"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def self.uses_libxml?(requirement = nil) # :nodoc:
|
188
|
+
return false unless VersionInfo.instance.libxml2?
|
189
|
+
return true unless requirement
|
190
|
+
Gem::Requirement.new(requirement).satisfied_by?(VersionInfo.instance.loaded_libxml_version)
|
191
|
+
end
|
192
|
+
|
193
|
+
def self.jruby? # :nodoc:
|
194
|
+
VersionInfo.instance.jruby?
|
195
|
+
end
|
196
|
+
|
197
|
+
# Ensure constants used in this file are loaded - see #1896
|
198
|
+
if Nokogiri.jruby?
|
199
|
+
require "nokogiri/jruby/dependencies"
|
200
|
+
end
|
201
|
+
require "nokogiri/extension"
|
202
|
+
|
203
|
+
# More complete version information about libxml
|
204
|
+
VERSION_INFO = VersionInfo.instance.to_hash
|
205
|
+
end
|
data/lib/nokogiri/version.rb
CHANGED
@@ -1,109 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
class VersionInfo # :nodoc:
|
6
|
-
def jruby?
|
7
|
-
::JRUBY_VERSION if RUBY_PLATFORM == "java"
|
8
|
-
end
|
9
|
-
|
10
|
-
def engine
|
11
|
-
defined?(RUBY_ENGINE) ? RUBY_ENGINE : "mri"
|
12
|
-
end
|
13
|
-
|
14
|
-
def loaded_parser_version
|
15
|
-
LIBXML_PARSER_VERSION.
|
16
|
-
scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first.
|
17
|
-
collect(&:to_i).
|
18
|
-
join(".")
|
19
|
-
end
|
20
|
-
|
21
|
-
def compiled_parser_version
|
22
|
-
LIBXML_VERSION
|
23
|
-
end
|
24
|
-
|
25
|
-
def libxml2?
|
26
|
-
defined?(LIBXML_VERSION)
|
27
|
-
end
|
28
|
-
|
29
|
-
def libxml2_using_system?
|
30
|
-
!libxml2_using_packaged?
|
31
|
-
end
|
32
|
-
|
33
|
-
def libxml2_using_packaged?
|
34
|
-
NOKOGIRI_USE_PACKAGED_LIBRARIES
|
35
|
-
end
|
36
|
-
|
37
|
-
def warnings
|
38
|
-
return [] unless libxml2?
|
39
|
-
|
40
|
-
if compiled_parser_version != loaded_parser_version
|
41
|
-
["Nokogiri was built against LibXML version #{compiled_parser_version}, but has dynamically loaded #{loaded_parser_version}"]
|
42
|
-
else
|
43
|
-
[]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def to_hash
|
48
|
-
hash_info = {}
|
49
|
-
hash_info["warnings"] = []
|
50
|
-
hash_info["nokogiri"] = Nokogiri::VERSION
|
51
|
-
hash_info["ruby"] = {}
|
52
|
-
hash_info["ruby"]["version"] = ::RUBY_VERSION
|
53
|
-
hash_info["ruby"]["platform"] = ::RUBY_PLATFORM
|
54
|
-
hash_info["ruby"]["description"] = ::RUBY_DESCRIPTION
|
55
|
-
hash_info["ruby"]["engine"] = engine
|
56
|
-
hash_info["ruby"]["jruby"] = jruby? if jruby?
|
57
|
-
|
58
|
-
if libxml2?
|
59
|
-
hash_info["libxml"] = {}
|
60
|
-
hash_info["libxml"]["binding"] = "extension"
|
61
|
-
if libxml2_using_packaged?
|
62
|
-
hash_info["libxml"]["source"] = "packaged"
|
63
|
-
hash_info["libxml"]["libxml2_path"] = NOKOGIRI_LIBXML2_PATH
|
64
|
-
hash_info["libxml"]["libxslt_path"] = NOKOGIRI_LIBXSLT_PATH
|
65
|
-
hash_info["libxml"]["libxml2_patches"] = NOKOGIRI_LIBXML2_PATCHES
|
66
|
-
hash_info["libxml"]["libxslt_patches"] = NOKOGIRI_LIBXSLT_PATCHES
|
67
|
-
else
|
68
|
-
hash_info["libxml"]["source"] = "system"
|
69
|
-
end
|
70
|
-
hash_info["libxml"]["compiled"] = compiled_parser_version
|
71
|
-
hash_info["libxml"]["loaded"] = loaded_parser_version
|
72
|
-
hash_info["warnings"] = warnings
|
73
|
-
elsif jruby?
|
74
|
-
hash_info["xerces"] = Nokogiri::XERCES_VERSION
|
75
|
-
hash_info["nekohtml"] = Nokogiri::NEKO_VERSION
|
76
|
-
end
|
77
|
-
|
78
|
-
hash_info
|
79
|
-
end
|
80
|
-
|
81
|
-
def to_markdown
|
82
|
-
begin
|
83
|
-
require "psych"
|
84
|
-
rescue LoadError
|
85
|
-
end
|
86
|
-
require "yaml"
|
87
|
-
"# Nokogiri (#{Nokogiri::VERSION})\n" +
|
88
|
-
YAML.dump(to_hash).each_line.map { |line| " #{line}" }.join
|
89
|
-
end
|
90
|
-
|
91
|
-
# FIXME: maybe switch to singleton?
|
92
|
-
@@instance = new
|
93
|
-
@@instance.warnings.each do |warning|
|
94
|
-
warn "WARNING: #{warning}"
|
95
|
-
end
|
96
|
-
def self.instance; @@instance; end
|
97
|
-
end
|
98
|
-
|
99
|
-
# More complete version information about libxml
|
100
|
-
VERSION_INFO = VersionInfo.instance.to_hash
|
101
|
-
|
102
|
-
def self.uses_libxml? # :nodoc:
|
103
|
-
VersionInfo.instance.libxml2?
|
104
|
-
end
|
105
|
-
|
106
|
-
def self.jruby? # :nodoc:
|
107
|
-
VersionInfo.instance.jruby?
|
108
|
-
end
|
109
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "version/constant"
|
3
|
+
require_relative "version/info"
|
data/lib/nokogiri/xml/attr.rb
CHANGED
data/lib/nokogiri/xml/builder.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Nokogiri
|
2
3
|
module XML
|
3
4
|
###
|
@@ -213,7 +214,7 @@ module Nokogiri
|
|
213
214
|
# xml.foo
|
214
215
|
# end
|
215
216
|
# end
|
216
|
-
#
|
217
|
+
#
|
217
218
|
# puts builder.to_xml
|
218
219
|
#
|
219
220
|
# Will output this xml:
|
@@ -244,13 +245,13 @@ module Nokogiri
|
|
244
245
|
#
|
245
246
|
# For example:
|
246
247
|
#
|
247
|
-
# doc = Nokogiri::XML(
|
248
|
-
# Nokogiri::XML::Builder.with(doc.
|
248
|
+
# doc = Nokogiri::XML(File.read('somedoc.xml'))
|
249
|
+
# Nokogiri::XML::Builder.with(doc.at_css('some_tag')) do |xml|
|
249
250
|
# # ... Use normal builder methods here ...
|
250
251
|
# xml.awesome # add the "awesome" tag below "some_tag"
|
251
252
|
# end
|
252
253
|
#
|
253
|
-
def self.with
|
254
|
+
def self.with(root, &block)
|
254
255
|
new({}, root, &block)
|
255
256
|
end
|
256
257
|
|
@@ -263,23 +264,25 @@ module Nokogiri
|
|
263
264
|
# Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
264
265
|
# ...
|
265
266
|
# end
|
266
|
-
def initialize
|
267
|
-
|
267
|
+
def initialize(options = {}, root = nil, &block)
|
268
268
|
if root
|
269
|
-
@doc
|
269
|
+
@doc = root.document
|
270
270
|
@parent = root
|
271
271
|
else
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
272
|
+
klassname = "::" + (self.class.name.split("::")[0..-2] + ["Document"]).join("::")
|
273
|
+
klass = begin
|
274
|
+
Object.const_get(klassname)
|
275
|
+
rescue NameError
|
276
|
+
Nokogiri::XML::Document
|
277
|
+
end
|
278
|
+
@parent = @doc = klass.new
|
276
279
|
end
|
277
280
|
|
278
|
-
@context
|
279
|
-
@arity
|
280
|
-
@ns
|
281
|
+
@context = nil
|
282
|
+
@arity = nil
|
283
|
+
@ns = nil
|
281
284
|
|
282
|
-
options.each do |k,v|
|
285
|
+
options.each do |k, v|
|
283
286
|
@doc.send(:"#{k}=", v)
|
284
287
|
end
|
285
288
|
|
@@ -287,7 +290,7 @@ module Nokogiri
|
|
287
290
|
|
288
291
|
@arity = block.arity
|
289
292
|
if @arity <= 0
|
290
|
-
@context = eval(
|
293
|
+
@context = eval("self", block.binding)
|
291
294
|
instance_eval(&block)
|
292
295
|
else
|
293
296
|
yield self
|
@@ -298,26 +301,26 @@ module Nokogiri
|
|
298
301
|
|
299
302
|
###
|
300
303
|
# Create a Text Node with content of +string+
|
301
|
-
def text
|
304
|
+
def text(string)
|
302
305
|
insert @doc.create_text_node(string)
|
303
306
|
end
|
304
307
|
|
305
308
|
###
|
306
309
|
# Create a CDATA Node with content of +string+
|
307
|
-
def cdata
|
310
|
+
def cdata(string)
|
308
311
|
insert doc.create_cdata(string)
|
309
312
|
end
|
310
313
|
|
311
314
|
###
|
312
315
|
# Create a Comment Node with content of +string+
|
313
|
-
def comment
|
316
|
+
def comment(string)
|
314
317
|
insert doc.create_comment(string)
|
315
318
|
end
|
316
319
|
|
317
320
|
###
|
318
321
|
# Build a tag that is associated with namespace +ns+. Raises an
|
319
322
|
# ArgumentError if +ns+ has not been defined higher in the tree.
|
320
|
-
def []
|
323
|
+
def [](ns)
|
321
324
|
if @parent != @doc
|
322
325
|
@ns = @parent.namespace_definitions.find { |x| x.prefix == ns.to_s }
|
323
326
|
end
|
@@ -348,15 +351,15 @@ module Nokogiri
|
|
348
351
|
|
349
352
|
###
|
350
353
|
# Append the given raw XML +string+ to the document
|
351
|
-
def <<
|
354
|
+
def <<(string)
|
352
355
|
@doc.fragment(string).children.each { |x| insert(x) }
|
353
356
|
end
|
354
357
|
|
355
|
-
def method_missing
|
358
|
+
def method_missing(method, *args, &block) # :nodoc:
|
356
359
|
if @context && @context.respond_to?(method)
|
357
360
|
@context.send(method, *args, &block)
|
358
361
|
else
|
359
|
-
node = @doc.create_element(method.to_s.sub(/[_!]$/,
|
362
|
+
node = @doc.create_element(method.to_s.sub(/[_!]$/, ""), *args) { |n|
|
360
363
|
# Set up the namespace
|
361
364
|
if @ns.is_a? Nokogiri::XML::Namespace
|
362
365
|
n.namespace = @ns
|
@@ -377,13 +380,14 @@ module Nokogiri
|
|
377
380
|
end
|
378
381
|
|
379
382
|
private
|
383
|
+
|
380
384
|
###
|
381
385
|
# Insert +node+ as a child of the current Node
|
382
386
|
def insert(node, &block)
|
383
387
|
node = @parent.add_child(node)
|
384
388
|
if block_given?
|
385
389
|
old_parent = @parent
|
386
|
-
@parent
|
390
|
+
@parent = node
|
387
391
|
@arity ||= block.arity
|
388
392
|
if @arity <= 0
|
389
393
|
instance_eval(&block)
|
@@ -396,16 +400,16 @@ module Nokogiri
|
|
396
400
|
end
|
397
401
|
|
398
402
|
class NodeBuilder # :nodoc:
|
399
|
-
def initialize
|
403
|
+
def initialize(node, doc_builder)
|
400
404
|
@node = node
|
401
405
|
@doc_builder = doc_builder
|
402
406
|
end
|
403
407
|
|
404
|
-
def []=
|
408
|
+
def []=(k, v)
|
405
409
|
@node[k] = v
|
406
410
|
end
|
407
411
|
|
408
|
-
def []
|
412
|
+
def [](k)
|
409
413
|
@node[k]
|
410
414
|
end
|
411
415
|
|
@@ -413,19 +417,19 @@ module Nokogiri
|
|
413
417
|
opts = args.last.is_a?(Hash) ? args.pop : {}
|
414
418
|
case method.to_s
|
415
419
|
when /^(.*)!$/
|
416
|
-
@node[
|
420
|
+
@node["id"] = $1
|
417
421
|
@node.content = args.first if args.first
|
418
422
|
when /^(.*)=/
|
419
423
|
@node[$1] = args.first
|
420
424
|
else
|
421
|
-
@node[
|
422
|
-
((@node[
|
425
|
+
@node["class"] =
|
426
|
+
((@node["class"] || "").split(/\s/) + [method.to_s]).join(" ")
|
423
427
|
@node.content = args.first if args.first
|
424
428
|
end
|
425
429
|
|
426
430
|
# Assign any extra options
|
427
|
-
opts.each do |k,v|
|
428
|
-
@node[k.to_s] = ((@node[k.to_s] ||
|
431
|
+
opts.each do |k, v|
|
432
|
+
@node[k.to_s] = ((@node[k.to_s] || "").split(/\s/) + [v]).join(" ")
|
429
433
|
end
|
430
434
|
|
431
435
|
if block_given?
|
data/lib/nokogiri/xml/cdata.rb
CHANGED