nokogiri 1.11.0.rc1-java → 1.11.2-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +1015 -947
- data/LICENSE.md +1 -1
- data/README.md +171 -94
- data/ext/java/nokogiri/EncodingHandler.java +78 -59
- data/ext/java/nokogiri/HtmlDocument.java +137 -114
- data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
- data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
- data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
- data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
- data/ext/java/nokogiri/NokogiriService.java +597 -526
- data/ext/java/nokogiri/XmlAttr.java +120 -96
- data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
- data/ext/java/nokogiri/XmlCdata.java +35 -26
- data/ext/java/nokogiri/XmlComment.java +48 -37
- data/ext/java/nokogiri/XmlDocument.java +642 -540
- data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
- data/ext/java/nokogiri/XmlDtd.java +450 -384
- data/ext/java/nokogiri/XmlElement.java +25 -18
- data/ext/java/nokogiri/XmlElementContent.java +345 -286
- data/ext/java/nokogiri/XmlElementDecl.java +126 -95
- data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
- data/ext/java/nokogiri/XmlEntityReference.java +51 -42
- data/ext/java/nokogiri/XmlNamespace.java +177 -145
- data/ext/java/nokogiri/XmlNode.java +1843 -1590
- data/ext/java/nokogiri/XmlNodeSet.java +361 -299
- data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
- data/ext/java/nokogiri/XmlReader.java +513 -418
- data/ext/java/nokogiri/XmlRelaxng.java +92 -72
- data/ext/java/nokogiri/XmlSaxParserContext.java +330 -280
- data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
- data/ext/java/nokogiri/XmlSchema.java +335 -210
- data/ext/java/nokogiri/XmlSyntaxError.java +113 -87
- data/ext/java/nokogiri/XmlText.java +57 -46
- data/ext/java/nokogiri/XmlXpathContext.java +242 -178
- data/ext/java/nokogiri/XsltStylesheet.java +282 -239
- data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +203 -160
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +65 -50
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
- data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +81 -59
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +121 -48
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -22
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
- data/ext/java/nokogiri/internals/ParserContext.java +206 -179
- data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
- data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
- data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -570
- data/ext/nokogiri/depend +37 -358
- data/ext/nokogiri/extconf.rb +585 -374
- 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 -93
- 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 +225 -163
- 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 +338 -286
- 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 -161
- data/lib/nokogiri.rb +4 -8
- data/lib/nokogiri/css/parser.rb +62 -62
- data/lib/nokogiri/css/parser.y +2 -2
- data/lib/nokogiri/css/parser_extras.rb +38 -36
- data/lib/nokogiri/css/xpath_visitor.rb +70 -42
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/document.rb +12 -26
- data/lib/nokogiri/html/document_fragment.rb +15 -15
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +2 -148
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +205 -0
- data/lib/nokogiri/xml/builder.rb +2 -2
- data/lib/nokogiri/xml/document.rb +48 -18
- data/lib/nokogiri/xml/document_fragment.rb +4 -6
- data/lib/nokogiri/xml/node.rb +599 -279
- data/lib/nokogiri/xml/parse_options.rb +6 -0
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/relax_ng.rb +6 -2
- data/lib/nokogiri/xml/schema.rb +12 -4
- data/lib/nokogiri/xml/searchable.rb +24 -16
- data/lib/nokogiri/xml/xpath.rb +1 -3
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- metadata +87 -158
- 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/nokogiri.h +0 -122
- 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
|
@@ -4,26 +4,26 @@ module Nokogiri
|
|
|
4
4
|
class DocumentFragment < Nokogiri::XML::DocumentFragment
|
|
5
5
|
####
|
|
6
6
|
# Create a Nokogiri::XML::DocumentFragment from +tags+, using +encoding+
|
|
7
|
-
def self.parse
|
|
7
|
+
def self.parse(tags, encoding = nil)
|
|
8
8
|
doc = HTML::Document.new
|
|
9
9
|
|
|
10
10
|
encoding ||= if tags.respond_to?(:encoding)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
20
20
|
|
|
21
21
|
doc.encoding = encoding
|
|
22
22
|
|
|
23
23
|
new(doc, tags)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def initialize
|
|
26
|
+
def initialize(document, tags = nil, ctx = nil)
|
|
27
27
|
return self unless tags
|
|
28
28
|
|
|
29
29
|
if ctx
|
|
@@ -33,13 +33,13 @@ module Nokogiri
|
|
|
33
33
|
self.errors = document.errors - preexisting_errors
|
|
34
34
|
else
|
|
35
35
|
# This is a horrible hack, but I don't care
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
path = if /^\s*?<body/i.match?(tags)
|
|
37
|
+
"/html/body"
|
|
38
38
|
else
|
|
39
|
-
|
|
39
|
+
"/html/body/node()"
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
temp_doc = HTML::Document.parse
|
|
42
|
+
temp_doc = HTML::Document.parse("<html><body>#{tags}", nil, document.encoding)
|
|
43
43
|
temp_doc.xpath(path).each { |child| child.parent = self }
|
|
44
44
|
self.errors = temp_doc.errors
|
|
45
45
|
end
|
data/lib/nokogiri/nokogiri.jar
CHANGED
|
Binary file
|
data/lib/nokogiri/version.rb
CHANGED
|
@@ -1,149 +1,3 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
VERSION = "1.11.0.rc1"
|
|
5
|
-
|
|
6
|
-
class VersionInfo # :nodoc:
|
|
7
|
-
def jruby?
|
|
8
|
-
::JRUBY_VERSION if RUBY_PLATFORM == "java"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def engine
|
|
12
|
-
defined?(RUBY_ENGINE) ? RUBY_ENGINE : "mri"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def loaded_libxml_version
|
|
16
|
-
Gem::Version.new(LIBXML_LOADED_VERSION.
|
|
17
|
-
scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first.
|
|
18
|
-
collect(&:to_i).
|
|
19
|
-
join("."))
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def compiled_libxml_version
|
|
23
|
-
Gem::Version.new LIBXML_COMPILED_VERSION
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def loaded_libxslt_version
|
|
27
|
-
Gem::Version.new(LIBXSLT_LOADED_VERSION.
|
|
28
|
-
scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first.
|
|
29
|
-
collect(&:to_i).
|
|
30
|
-
join("."))
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def compiled_libxslt_version
|
|
34
|
-
Gem::Version.new LIBXSLT_COMPILED_VERSION
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def libxml2?
|
|
38
|
-
defined?(LIBXML_COMPILED_VERSION)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def libxml2_using_system?
|
|
42
|
-
!libxml2_using_packaged?
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def libxml2_using_packaged?
|
|
46
|
-
NOKOGIRI_USE_PACKAGED_LIBRARIES
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def warnings
|
|
50
|
-
warnings = []
|
|
51
|
-
|
|
52
|
-
if libxml2?
|
|
53
|
-
if compiled_libxml_version != loaded_libxml_version
|
|
54
|
-
warnings << "Nokogiri was built against libxml version #{compiled_libxml_version}, but has dynamically loaded #{loaded_libxml_version}"
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
if compiled_libxslt_version != loaded_libxslt_version
|
|
58
|
-
warnings << "Nokogiri was built against libxslt version #{compiled_libxslt_version}, but has dynamically loaded #{loaded_libxslt_version}"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
warnings
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def to_hash
|
|
66
|
-
{}.tap do |vi|
|
|
67
|
-
vi["warnings"] = []
|
|
68
|
-
vi["nokogiri"] = Nokogiri::VERSION
|
|
69
|
-
vi["ruby"] = {}.tap do |ruby|
|
|
70
|
-
ruby["version"] = ::RUBY_VERSION
|
|
71
|
-
ruby["platform"] = ::RUBY_PLATFORM
|
|
72
|
-
ruby["description"] = ::RUBY_DESCRIPTION
|
|
73
|
-
ruby["engine"] = engine
|
|
74
|
-
ruby["jruby"] = jruby? if jruby?
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
if libxml2?
|
|
78
|
-
vi["libxml"] = {}.tap do |libxml|
|
|
79
|
-
if libxml2_using_packaged?
|
|
80
|
-
libxml["source"] = "packaged"
|
|
81
|
-
libxml["patches"] = NOKOGIRI_LIBXML2_PATCHES
|
|
82
|
-
else
|
|
83
|
-
libxml["source"] = "system"
|
|
84
|
-
end
|
|
85
|
-
libxml["compiled"] = compiled_libxml_version.to_s
|
|
86
|
-
libxml["loaded"] = loaded_libxml_version.to_s
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
vi["libxslt"] = {}.tap do |libxslt|
|
|
90
|
-
if libxml2_using_packaged?
|
|
91
|
-
libxslt["source"] = "packaged"
|
|
92
|
-
libxslt["patches"] = NOKOGIRI_LIBXSLT_PATCHES
|
|
93
|
-
else
|
|
94
|
-
libxslt["source"] = "system"
|
|
95
|
-
end
|
|
96
|
-
libxslt["compiled"] = compiled_libxslt_version.to_s
|
|
97
|
-
libxslt["loaded"] = loaded_libxslt_version.to_s
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
vi["warnings"] = warnings
|
|
101
|
-
elsif jruby?
|
|
102
|
-
vi["xerces"] = Nokogiri::XERCES_VERSION
|
|
103
|
-
vi["nekohtml"] = Nokogiri::NEKO_VERSION
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def to_markdown
|
|
109
|
-
begin
|
|
110
|
-
require "psych"
|
|
111
|
-
rescue LoadError
|
|
112
|
-
end
|
|
113
|
-
require "yaml"
|
|
114
|
-
"# Nokogiri (#{Nokogiri::VERSION})\n" +
|
|
115
|
-
YAML.dump(to_hash).each_line.map { |line| " #{line}" }.join
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# FIXME: maybe switch to singleton?
|
|
119
|
-
@@instance = new
|
|
120
|
-
@@instance.warnings.each do |warning|
|
|
121
|
-
warn "WARNING: #{warning}"
|
|
122
|
-
end
|
|
123
|
-
def self.instance; @@instance; end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def self.uses_libxml?(requirement = nil) # :nodoc:
|
|
127
|
-
return false unless VersionInfo.instance.libxml2?
|
|
128
|
-
return true unless requirement
|
|
129
|
-
return Gem::Requirement.new(requirement).satisfied_by?(VersionInfo.instance.loaded_libxml_version)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def self.jruby? # :nodoc:
|
|
133
|
-
VersionInfo.instance.jruby?
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
# Ensure constants used in this file are loaded
|
|
137
|
-
if Nokogiri.jruby?
|
|
138
|
-
require "nokogiri/jruby/dependencies"
|
|
139
|
-
end
|
|
140
|
-
begin
|
|
141
|
-
RUBY_VERSION =~ /(\d+\.\d+)/
|
|
142
|
-
require "nokogiri/#{$1}/nokogiri"
|
|
143
|
-
rescue LoadError
|
|
144
|
-
require "nokogiri/nokogiri"
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
# More complete version information about libxml
|
|
148
|
-
VERSION_INFO = VersionInfo.instance.to_hash
|
|
149
|
-
end
|
|
2
|
+
require_relative "version/constant"
|
|
3
|
+
require_relative "version/info"
|
|
@@ -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/xml/builder.rb
CHANGED
|
@@ -245,8 +245,8 @@ module Nokogiri
|
|
|
245
245
|
#
|
|
246
246
|
# For example:
|
|
247
247
|
#
|
|
248
|
-
# doc = Nokogiri::XML(
|
|
249
|
-
# 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|
|
|
250
250
|
# # ... Use normal builder methods here ...
|
|
251
251
|
# xml.awesome # add the "awesome" tag below "some_tag"
|
|
252
252
|
# end
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
# coding: utf-8
|
|
1
2
|
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'pathname'
|
|
5
|
+
|
|
2
6
|
module Nokogiri
|
|
3
7
|
module XML
|
|
4
8
|
##
|
|
@@ -44,9 +48,11 @@ module Nokogiri
|
|
|
44
48
|
#
|
|
45
49
|
def self.parse string_or_io, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML
|
|
46
50
|
options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
|
|
47
|
-
|
|
51
|
+
|
|
48
52
|
yield options if block_given?
|
|
49
53
|
|
|
54
|
+
url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil
|
|
55
|
+
|
|
50
56
|
if empty_doc?(string_or_io)
|
|
51
57
|
if options.strict?
|
|
52
58
|
raise Nokogiri::XML::SyntaxError.new("Empty document")
|
|
@@ -56,12 +62,17 @@ module Nokogiri
|
|
|
56
62
|
end
|
|
57
63
|
|
|
58
64
|
doc = if string_or_io.respond_to?(:read)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
if string_or_io.is_a?(Pathname)
|
|
66
|
+
# resolve the Pathname to the file and open it as an IO object, see #2110
|
|
67
|
+
string_or_io = string_or_io.expand_path.open
|
|
68
|
+
url ||= string_or_io.path
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
read_io(string_or_io, url, encoding, options.to_i)
|
|
72
|
+
else
|
|
73
|
+
# read_memory pukes on empty docs
|
|
74
|
+
read_memory(string_or_io, url, encoding, options.to_i)
|
|
75
|
+
end
|
|
65
76
|
|
|
66
77
|
# do xinclude processing
|
|
67
78
|
doc.do_xinclude(options) if options.xinclude?
|
|
@@ -69,6 +80,35 @@ module Nokogiri
|
|
|
69
80
|
return doc
|
|
70
81
|
end
|
|
71
82
|
|
|
83
|
+
##
|
|
84
|
+
# @!method wrap(java_document)
|
|
85
|
+
# @!scope class
|
|
86
|
+
#
|
|
87
|
+
# Create a {Document} using an existing Java DOM document object.
|
|
88
|
+
#
|
|
89
|
+
# The returned {Document} shares the same underlying data structure as the Java object, so
|
|
90
|
+
# changes in one are reflected in the other.
|
|
91
|
+
#
|
|
92
|
+
# @param java_document [Java::OrgW3cDom::Document]
|
|
93
|
+
# @return [Nokogiri::XML::Document]
|
|
94
|
+
# @note This method is only available when running JRuby.
|
|
95
|
+
# @note The class +Java::OrgW3cDom::Document+ is also accessible as +org.w3c.dom.Document+.
|
|
96
|
+
# @see #to_java
|
|
97
|
+
|
|
98
|
+
##
|
|
99
|
+
# @!method to_java()
|
|
100
|
+
#
|
|
101
|
+
# Returns the underlying Java DOM document object for the {Document}.
|
|
102
|
+
#
|
|
103
|
+
# The returned Java object shares the same underlying data structure as the {Document}, so
|
|
104
|
+
# changes in one are reflected in the other.
|
|
105
|
+
#
|
|
106
|
+
# @return [Java::OrgW3cDom::Document]
|
|
107
|
+
# @note This method is only available when running JRuby.
|
|
108
|
+
# @note The class +Java::OrgW3cDom::Document+ is also accessible as +org.w3c.dom.Document+.
|
|
109
|
+
# @see .wrap
|
|
110
|
+
|
|
111
|
+
|
|
72
112
|
# A list of Nokogiri::XML::SyntaxError found when parsing a document
|
|
73
113
|
attr_accessor :errors
|
|
74
114
|
|
|
@@ -252,24 +292,14 @@ module Nokogiri
|
|
|
252
292
|
end
|
|
253
293
|
alias :<< :add_child
|
|
254
294
|
|
|
255
|
-
##
|
|
256
|
-
# +JRuby+
|
|
257
|
-
# Wraps Java's org.w3c.dom.document and returns Nokogiri::XML::Document
|
|
258
|
-
def self.wrap(document) end if false # native-ext provides Document.wrap
|
|
259
|
-
|
|
260
|
-
##
|
|
261
|
-
# +JRuby+
|
|
262
|
-
# Returns Java's org.w3c.dom.document of this Document.
|
|
263
|
-
def to_java; end if false # JRuby provides #to_java
|
|
264
|
-
|
|
265
295
|
private
|
|
296
|
+
|
|
266
297
|
def self.empty_doc? string_or_io
|
|
267
298
|
string_or_io.nil? ||
|
|
268
299
|
(string_or_io.respond_to?(:empty?) && string_or_io.empty?) ||
|
|
269
300
|
(string_or_io.respond_to?(:eof?) && string_or_io.eof?)
|
|
270
301
|
end
|
|
271
302
|
|
|
272
|
-
# @private
|
|
273
303
|
IMPLIED_XPATH_CONTEXTS = [ '//'.freeze ].freeze # :nodoc:
|
|
274
304
|
|
|
275
305
|
def inspect_attributes
|