nokogiri 1.4.7-x86-mswin32-60 → 1.5.0-x86-mswin32-60
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.
- data/CHANGELOG.ja.rdoc +59 -1
- data/CHANGELOG.rdoc +51 -2
- data/Manifest.txt +66 -66
- data/README.ja.rdoc +4 -0
- data/README.rdoc +31 -3
- data/Rakefile +111 -135
- data/bin/nokogiri +1 -2
- data/ext/nokogiri/extconf.rb +9 -3
- data/ext/nokogiri/nokogiri.c +21 -3
- data/ext/nokogiri/nokogiri.h +0 -2
- data/ext/nokogiri/xml_node.c +0 -6
- data/ext/nokogiri/xml_relax_ng.c +0 -7
- data/ext/nokogiri/xml_sax_parser.c +9 -4
- data/ext/nokogiri/xslt_stylesheet.c +5 -1
- data/lib/nokogiri.rb +19 -25
- data/lib/nokogiri/1.8/nokogiri.so +0 -0
- data/lib/nokogiri/1.9/nokogiri.so +0 -0
- data/lib/nokogiri/css.rb +0 -1
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/html/document.rb +9 -2
- data/lib/nokogiri/html/element_description_defaults.rb +671 -0
- data/lib/nokogiri/version.rb +76 -31
- data/lib/nokogiri/xml/attribute_decl.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +7 -0
- data/lib/nokogiri/xml/document.rb +17 -1
- data/lib/nokogiri/xml/document_fragment.rb +14 -0
- data/lib/nokogiri/xml/dtd.rb +1 -1
- data/lib/nokogiri/xml/element_decl.rb +1 -1
- data/lib/nokogiri/xml/entity_decl.rb +1 -1
- data/lib/nokogiri/xml/node.rb +39 -15
- data/lib/nokogiri/xml/node/save_options.rb +14 -5
- data/lib/nokogiri/xml/node_set.rb +7 -0
- data/lib/nokogiri/xml/reader.rb +2 -2
- data/lib/nokogiri/xml/sax/document.rb +2 -2
- data/lib/nokogiri/xslt/stylesheet.rb +1 -1
- data/nokogiri_help_responses.md +40 -0
- data/tasks/cross_compile.rb +134 -155
- data/tasks/nokogiri.org.rb +18 -0
- data/tasks/test.rb +2 -2
- data/test/files/metacharset.html +10 -0
- data/test/files/noencoding.html +47 -0
- data/test/helper.rb +2 -1
- data/test/html/sax/test_parser.rb +22 -5
- data/test/html/test_document.rb +21 -2
- data/test/html/test_document_encoding.rb +9 -1
- data/test/html/test_document_fragment.rb +5 -3
- data/test/html/test_element_description.rb +4 -2
- data/test/test_memory_leak.rb +4 -39
- data/test/test_nokogiri.rb +14 -20
- data/test/test_reader.rb +12 -8
- data/test/xml/node/test_save_options.rb +10 -2
- data/test/xml/sax/test_parser.rb +14 -7
- data/test/xml/test_attribute_decl.rb +7 -3
- data/test/xml/test_builder.rb +17 -0
- data/test/xml/test_document.rb +31 -4
- data/test/xml/test_dtd.rb +13 -3
- data/test/xml/test_element_content.rb +1 -1
- data/test/xml/test_element_decl.rb +1 -1
- data/test/xml/test_entity_decl.rb +12 -10
- data/test/xml/test_namespace.rb +7 -5
- data/test/xml/test_node.rb +21 -10
- data/test/xml/test_node_reparenting.rb +16 -3
- data/test/xml/test_node_set.rb +34 -0
- data/test/xslt/test_custom_functions.rb +2 -2
- data/test/xslt/test_exception_handling.rb +37 -0
- metadata +110 -88
- data/lib/nokogiri/ffi/encoding_handler.rb +0 -42
- data/lib/nokogiri/ffi/html/document.rb +0 -28
- data/lib/nokogiri/ffi/html/element_description.rb +0 -81
- data/lib/nokogiri/ffi/html/entity_lookup.rb +0 -16
- data/lib/nokogiri/ffi/html/sax/parser_context.rb +0 -38
- data/lib/nokogiri/ffi/io_callbacks.rb +0 -42
- data/lib/nokogiri/ffi/libxml.rb +0 -420
- data/lib/nokogiri/ffi/structs/common_node.rb +0 -38
- data/lib/nokogiri/ffi/structs/html_elem_desc.rb +0 -24
- data/lib/nokogiri/ffi/structs/html_entity_desc.rb +0 -13
- data/lib/nokogiri/ffi/structs/xml_alloc.rb +0 -16
- data/lib/nokogiri/ffi/structs/xml_attr.rb +0 -20
- data/lib/nokogiri/ffi/structs/xml_attribute.rb +0 -27
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +0 -16
- data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +0 -11
- data/lib/nokogiri/ffi/structs/xml_document.rb +0 -117
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +0 -28
- data/lib/nokogiri/ffi/structs/xml_element.rb +0 -26
- data/lib/nokogiri/ffi/structs/xml_element_content.rb +0 -17
- data/lib/nokogiri/ffi/structs/xml_entity.rb +0 -32
- data/lib/nokogiri/ffi/structs/xml_enumeration.rb +0 -12
- data/lib/nokogiri/ffi/structs/xml_node.rb +0 -28
- data/lib/nokogiri/ffi/structs/xml_node_set.rb +0 -53
- data/lib/nokogiri/ffi/structs/xml_notation.rb +0 -11
- data/lib/nokogiri/ffi/structs/xml_ns.rb +0 -15
- data/lib/nokogiri/ffi/structs/xml_parser_context.rb +0 -20
- data/lib/nokogiri/ffi/structs/xml_parser_input.rb +0 -19
- data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +0 -14
- data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +0 -51
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +0 -124
- data/lib/nokogiri/ffi/structs/xml_schema.rb +0 -13
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +0 -31
- data/lib/nokogiri/ffi/structs/xml_text_reader.rb +0 -12
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +0 -38
- data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +0 -35
- data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +0 -20
- data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +0 -13
- data/lib/nokogiri/ffi/weak_bucket.rb +0 -40
- data/lib/nokogiri/ffi/xml/attr.rb +0 -41
- data/lib/nokogiri/ffi/xml/attribute_decl.rb +0 -27
- data/lib/nokogiri/ffi/xml/cdata.rb +0 -19
- data/lib/nokogiri/ffi/xml/comment.rb +0 -18
- data/lib/nokogiri/ffi/xml/document.rb +0 -174
- data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -21
- data/lib/nokogiri/ffi/xml/dtd.rb +0 -67
- data/lib/nokogiri/ffi/xml/element_content.rb +0 -43
- data/lib/nokogiri/ffi/xml/element_decl.rb +0 -19
- data/lib/nokogiri/ffi/xml/entity_decl.rb +0 -36
- data/lib/nokogiri/ffi/xml/entity_reference.rb +0 -19
- data/lib/nokogiri/ffi/xml/namespace.rb +0 -44
- data/lib/nokogiri/ffi/xml/node.rb +0 -559
- data/lib/nokogiri/ffi/xml/node_set.rb +0 -150
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +0 -20
- data/lib/nokogiri/ffi/xml/reader.rb +0 -236
- data/lib/nokogiri/ffi/xml/relax_ng.rb +0 -85
- data/lib/nokogiri/ffi/xml/sax/parser.rb +0 -143
- data/lib/nokogiri/ffi/xml/sax/parser_context.rb +0 -79
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +0 -51
- data/lib/nokogiri/ffi/xml/schema.rb +0 -109
- data/lib/nokogiri/ffi/xml/syntax_error.rb +0 -98
- data/lib/nokogiri/ffi/xml/text.rb +0 -18
- data/lib/nokogiri/ffi/xml/xpath.rb +0 -9
- data/lib/nokogiri/ffi/xml/xpath_context.rb +0 -153
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +0 -77
- data/lib/nokogiri/version_warning.rb +0 -14
- data/test/ffi/test_document.rb +0 -35
@@ -1,18 +0,0 @@
|
|
1
|
-
module Nokogiri
|
2
|
-
module XML
|
3
|
-
class Text < CharacterData
|
4
|
-
|
5
|
-
def self.new(string, document, *rest) # :nodoc:
|
6
|
-
node_ptr = LibXML.xmlNewText(string)
|
7
|
-
node_cstruct = LibXML::XmlNode.new(node_ptr)
|
8
|
-
node_cstruct[:doc] = document.cstruct[:doc]
|
9
|
-
|
10
|
-
node = Node.wrap(node_cstruct, self)
|
11
|
-
node.send :initialize, string, document, *rest
|
12
|
-
yield node if block_given?
|
13
|
-
node
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,153 +0,0 @@
|
|
1
|
-
module Nokogiri
|
2
|
-
module XML
|
3
|
-
class XPathContext
|
4
|
-
|
5
|
-
attr_accessor :cstruct # :nodoc:
|
6
|
-
|
7
|
-
def register_ns(prefix, uri) # :nodoc:
|
8
|
-
LibXML.xmlXPathRegisterNs(cstruct, prefix, uri)
|
9
|
-
end
|
10
|
-
|
11
|
-
def register_variable(name, value) # :nodoc:
|
12
|
-
xml_value = LibXML.xmlXPathNewCString(value);
|
13
|
-
LibXML.xmlXPathRegisterVariable(cstruct, name, xml_value);
|
14
|
-
end
|
15
|
-
|
16
|
-
def evaluate(search_path, xpath_handler=nil) # :nodoc:
|
17
|
-
lookup = nil # to keep lambda in scope long enough to avoid a possible GC tragedy
|
18
|
-
query = search_path.to_s
|
19
|
-
|
20
|
-
if xpath_handler
|
21
|
-
lookup = lambda do |ctx, name, uri|
|
22
|
-
return nil unless xpath_handler.respond_to?(name)
|
23
|
-
ruby_funcall name, xpath_handler
|
24
|
-
end
|
25
|
-
LibXML.xmlXPathRegisterFuncLookup(cstruct, lookup, nil);
|
26
|
-
end
|
27
|
-
|
28
|
-
exception_handler = lambda do |ctx, error|
|
29
|
-
raise XPath::SyntaxError.wrap(error)
|
30
|
-
end
|
31
|
-
LibXML.xmlResetLastError()
|
32
|
-
LibXML.xmlSetStructuredErrorFunc(nil, exception_handler)
|
33
|
-
|
34
|
-
generic_exception_handler = lambda do |ctx, msg|
|
35
|
-
raise RuntimeError.new(msg) # TODO: varargs
|
36
|
-
end
|
37
|
-
LibXML.xmlSetGenericErrorFunc(nil, generic_exception_handler)
|
38
|
-
|
39
|
-
xpath_ptr = LibXML.xmlXPathEvalExpression(query, cstruct)
|
40
|
-
|
41
|
-
LibXML.xmlSetStructuredErrorFunc(nil, nil)
|
42
|
-
LibXML.xmlSetGenericErrorFunc(nil, nil)
|
43
|
-
|
44
|
-
if xpath_ptr.null?
|
45
|
-
error = LibXML.xmlGetLastError()
|
46
|
-
raise XPath::SyntaxError.wrap(error)
|
47
|
-
end
|
48
|
-
|
49
|
-
xpath = XML::XPath.new
|
50
|
-
xpath.cstruct = LibXML::XmlXpathObject.new(xpath_ptr)
|
51
|
-
xpath.document = cstruct.document.ruby_doc
|
52
|
-
|
53
|
-
case xpath.cstruct[:type]
|
54
|
-
when LibXML::XmlXpathObject::XPATH_NODESET
|
55
|
-
if xpath.cstruct[:nodesetval].null?
|
56
|
-
NodeSet.new(xpath.document)
|
57
|
-
else
|
58
|
-
NodeSet.wrap(xpath.cstruct[:nodesetval], xpath.document)
|
59
|
-
end
|
60
|
-
when LibXML::XmlXpathObject::XPATH_STRING
|
61
|
-
xpath.cstruct[:stringval]
|
62
|
-
when LibXML::XmlXpathObject::XPATH_NUMBER
|
63
|
-
xpath.cstruct[:floatval]
|
64
|
-
when LibXML::XmlXpathObject::XPATH_BOOLEAN
|
65
|
-
0 != xpath.cstruct[:boolval]
|
66
|
-
else
|
67
|
-
NodeSet.new(xpath.document)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.new(node) # :nodoc:
|
72
|
-
LibXML.xmlXPathInit()
|
73
|
-
|
74
|
-
ptr = LibXML.xmlXPathNewContext(node.cstruct[:doc])
|
75
|
-
|
76
|
-
ctx = allocate
|
77
|
-
ctx.cstruct = LibXML::XmlXpathContext.new(ptr)
|
78
|
-
ctx.cstruct[:node] = node.cstruct
|
79
|
-
ctx
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
|
-
|
84
|
-
#
|
85
|
-
# returns a lambda that will call the handler function with marshalled parameters
|
86
|
-
#
|
87
|
-
def ruby_funcall(name, xpath_handler) # :nodoc:
|
88
|
-
lambda do |ctx, nargs|
|
89
|
-
parser_context = LibXML::XmlXpathParserContext.new(ctx)
|
90
|
-
context_cstruct = parser_context.context
|
91
|
-
document = context_cstruct.document.ruby_doc
|
92
|
-
|
93
|
-
params = []
|
94
|
-
|
95
|
-
nargs.times do |j|
|
96
|
-
obj = LibXML::XmlXpathObject.new(LibXML.valuePop(ctx))
|
97
|
-
case obj[:type]
|
98
|
-
when LibXML::XmlXpathObject::XPATH_STRING
|
99
|
-
params.unshift obj[:stringval]
|
100
|
-
when LibXML::XmlXpathObject::XPATH_BOOLEAN
|
101
|
-
params.unshift obj[:boolval] == 1
|
102
|
-
when LibXML::XmlXpathObject::XPATH_NUMBER
|
103
|
-
params.unshift obj[:floatval]
|
104
|
-
when LibXML::XmlXpathObject::XPATH_NODESET
|
105
|
-
params.unshift NodeSet.wrap(obj[:nodesetval], document)
|
106
|
-
else
|
107
|
-
char_ptr = params.unshift LibXML.xmlXPathCastToString(obj)
|
108
|
-
string = char_ptr.read_string
|
109
|
-
LibXML.xmlFree(char_ptr)
|
110
|
-
string
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
result = xpath_handler.send(name, *params)
|
115
|
-
|
116
|
-
case result.class.to_s
|
117
|
-
when Fixnum.to_s, Float.to_s, Bignum.to_s
|
118
|
-
LibXML.xmlXPathReturnNumber(ctx, result)
|
119
|
-
when String.to_s
|
120
|
-
LibXML.xmlXPathReturnString(
|
121
|
-
ctx,
|
122
|
-
LibXML.xmlXPathWrapCString(result)
|
123
|
-
)
|
124
|
-
when TrueClass.to_s
|
125
|
-
LibXML.xmlXPathReturnTrue(ctx)
|
126
|
-
when FalseClass.to_s
|
127
|
-
LibXML.xmlXPathReturnFalse(ctx)
|
128
|
-
when NilClass.to_s
|
129
|
-
;
|
130
|
-
when Array.to_s
|
131
|
-
node_set = XML::NodeSet.new(document, result)
|
132
|
-
LibXML.xmlXPathReturnNodeSet(
|
133
|
-
ctx,
|
134
|
-
LibXML.xmlXPathNodeSetMerge(nil, node_set.cstruct)
|
135
|
-
)
|
136
|
-
else
|
137
|
-
if result.is_a?(XML::NodeSet)
|
138
|
-
LibXML.xmlXPathReturnNodeSet(
|
139
|
-
ctx,
|
140
|
-
LibXML.xmlXPathNodeSetMerge(nil, result.cstruct)
|
141
|
-
)
|
142
|
-
else
|
143
|
-
raise RuntimeError.new("Invalid return type #{result.class.inspect}")
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
nil
|
148
|
-
end # lambda
|
149
|
-
end # ruby_funcall
|
150
|
-
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
module Nokogiri
|
2
|
-
module XSLT
|
3
|
-
@modules = {}
|
4
|
-
|
5
|
-
@method_caller = lambda do |context, nargs|
|
6
|
-
# TODO
|
7
|
-
end
|
8
|
-
|
9
|
-
@init_func = lambda do |context, uri|
|
10
|
-
klass = @modules[uri]
|
11
|
-
klass.instance_methods(false).each do |method_name|
|
12
|
-
LibXML.xsltRegisterExtFunction(context, method_name, uri, @method_caller)
|
13
|
-
end
|
14
|
-
klass.new
|
15
|
-
end
|
16
|
-
|
17
|
-
@shutdown_func = lambda do |context, uri, data|
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.register(uri, klass) # :nodoc:
|
21
|
-
raise NotImplementedError.new("sorry, you should implement me.")
|
22
|
-
end
|
23
|
-
|
24
|
-
class Stylesheet
|
25
|
-
|
26
|
-
attr_accessor :cstruct # :nodoc:
|
27
|
-
|
28
|
-
def self.parse_stylesheet_doc(document) # :nodoc:
|
29
|
-
LibXML.exsltRegisterAll
|
30
|
-
|
31
|
-
generic_exception_handler = lambda do |ctx, msg|
|
32
|
-
raise RuntimeError.new(msg) # TODO: varargs
|
33
|
-
end
|
34
|
-
LibXML.xsltSetGenericErrorFunc(nil, generic_exception_handler)
|
35
|
-
|
36
|
-
ss = LibXML.xsltParseStylesheetDoc(LibXML.xmlCopyDoc(document.cstruct, 1)) # 1 => recursive
|
37
|
-
|
38
|
-
LibXML.xsltSetGenericErrorFunc(nil, nil)
|
39
|
-
|
40
|
-
obj = allocate
|
41
|
-
obj.cstruct = LibXML::XsltStylesheet.new(ss)
|
42
|
-
obj
|
43
|
-
end
|
44
|
-
|
45
|
-
def serialize(document) # :nodoc:
|
46
|
-
buf_ptr = FFI::Buffer.new :pointer
|
47
|
-
buf_len = FFI::Buffer.new :int
|
48
|
-
LibXML.xsltSaveResultToString(buf_ptr, buf_len, document.cstruct, cstruct)
|
49
|
-
buf = Nokogiri::LibXML::XmlAlloc.new(buf_ptr.get_pointer(0))
|
50
|
-
buf.pointer.read_string(buf_len.get_int(0))
|
51
|
-
end
|
52
|
-
|
53
|
-
def transform(document, params=[]) # :nodoc:
|
54
|
-
unless document.kind_of? Nokogiri::XML::Document
|
55
|
-
raise ArgumentError, "argument must be a Nokogiri::XML::Document"
|
56
|
-
end
|
57
|
-
|
58
|
-
params = params.to_a.flatten if params.is_a?(Hash)
|
59
|
-
raise(TypeError) unless params.is_a?(Array)
|
60
|
-
|
61
|
-
param_arr = FFI::MemoryPointer.new(:pointer, params.length + 1, false)
|
62
|
-
|
63
|
-
# Keep the MemoryPointer instances alive until after the call
|
64
|
-
ptrs = params.map { |param | FFI::MemoryPointer.from_string(param.to_s) }
|
65
|
-
param_arr.put_array_of_pointer(0, ptrs)
|
66
|
-
|
67
|
-
# Terminate the list with a NULL pointer
|
68
|
-
param_arr.put_pointer(LibXML.pointer_offset(params.length), nil)
|
69
|
-
|
70
|
-
ptr = LibXML.xsltApplyStylesheet(cstruct, document.cstruct, param_arr)
|
71
|
-
raise(RuntimeError, "could not perform xslt transform on document") if ptr.null?
|
72
|
-
|
73
|
-
XML::Document.wrap(ptr)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Nokogiri
|
2
|
-
if self.is_2_6_16?
|
3
|
-
VERSION_INFO['warnings'] << "libxml 2.6.16 is old and buggy."
|
4
|
-
if !defined?(I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2)
|
5
|
-
warn <<-eom
|
6
|
-
HI. You're using libxml2 version 2.6.16 which is over 4 years old and has
|
7
|
-
plenty of bugs. We suggest that for maximum HTML/XML parsing pleasure, you
|
8
|
-
upgrade your version of libxml2 and re-install nokogiri. If you like using
|
9
|
-
libxml2 version 2.6.16, but don't like this warning, please define the constant
|
10
|
-
I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 before requring nokogiri.
|
11
|
-
eom
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/test/ffi/test_document.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
if defined?(Nokogiri::LibXML)
|
4
|
-
|
5
|
-
class FFI::TestDocument < Nokogiri::TestCase
|
6
|
-
|
7
|
-
def test_ruby_doc_reflection
|
8
|
-
doc = Nokogiri::XML("<root><foo>foo</foo></root>")
|
9
|
-
assert_equal doc, doc.cstruct.ruby_doc
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_ruby_doc_setter
|
13
|
-
doc = Nokogiri::XML("<root><foo>foo</foo></root>")
|
14
|
-
foo = "foobar"
|
15
|
-
doc.cstruct.ruby_doc = foo
|
16
|
-
assert_equal foo, doc.cstruct.ruby_doc
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_unlinked_nodes
|
20
|
-
doc = Nokogiri::XML("<root><foo>foo</foo></root>")
|
21
|
-
assert_instance_of Nokogiri::LibXML::XmlNodeSetCast, doc.cstruct.unlinked_nodes
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_unlinked_nodes_contains_unlinked_nodes
|
25
|
-
doc = Nokogiri::XML("<root><foo>foo</foo></root>")
|
26
|
-
node = doc.xpath('//foo').first
|
27
|
-
assert_equal 0, doc.cstruct.unlinked_nodes[:nodeNr]
|
28
|
-
node.unlink
|
29
|
-
assert_equal 1, doc.cstruct.unlinked_nodes[:nodeNr]
|
30
|
-
assert_equal node.cstruct.pointer, doc.cstruct.unlinked_nodes[:nodeTab].get_pointer(0)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|