nokogiri 1.4.7-java → 1.5.0.beta.1-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- data.tar.gz.sig +0 -0
- data/CHANGELOG.ja.rdoc +8 -83
- data/CHANGELOG.rdoc +6 -80
- data/Manifest.txt +4 -74
- data/README.ja.rdoc +5 -1
- data/README.rdoc +8 -22
- data/Rakefile +79 -60
- data/bin/nokogiri +1 -6
- data/deps.rip +5 -0
- data/ext/nokogiri/extconf.rb +32 -53
- data/ext/nokogiri/nokogiri.c +0 -2
- data/ext/nokogiri/nokogiri.h +0 -9
- data/ext/nokogiri/xml_document.c +0 -14
- data/ext/nokogiri/xml_dtd.c +2 -2
- data/ext/nokogiri/xml_io.c +7 -32
- data/ext/nokogiri/xml_node.c +31 -103
- data/ext/nokogiri/xml_node_set.c +8 -8
- data/ext/nokogiri/xml_reader.c +1 -20
- data/ext/nokogiri/xml_sax_parser.c +3 -5
- data/ext/nokogiri/xml_sax_parser_context.c +0 -40
- data/ext/nokogiri/xml_xpath_context.c +2 -35
- data/ext/nokogiri/xslt_stylesheet.c +6 -124
- data/lib/isorelax.jar +0 -0
- data/lib/jing.jar +0 -0
- data/lib/nekodtd.jar +0 -0
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri.rb +7 -3
- data/lib/nokogiri/css.rb +3 -6
- data/lib/nokogiri/css/generated_parser.rb +669 -0
- data/lib/nokogiri/css/generated_tokenizer.rb +145 -0
- data/lib/nokogiri/css/parser.rb +70 -665
- data/lib/nokogiri/css/parser.y +1 -6
- data/lib/nokogiri/css/tokenizer.rb +3 -148
- data/lib/nokogiri/css/tokenizer.rex +1 -1
- data/lib/nokogiri/css/xpath_visitor.rb +14 -16
- data/lib/nokogiri/decorators/slop.rb +3 -5
- data/lib/nokogiri/html.rb +3 -2
- data/lib/nokogiri/html/document.rb +18 -134
- data/lib/nokogiri/html/document_fragment.rb +21 -26
- data/lib/nokogiri/html/element_description_defaults.rb +671 -0
- data/lib/nokogiri/html/sax/parser.rb +2 -6
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +4 -9
- data/lib/nokogiri/xml/attribute_decl.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +1 -1
- data/lib/nokogiri/xml/document.rb +3 -27
- data/lib/nokogiri/xml/document_fragment.rb +2 -9
- data/lib/nokogiri/xml/dtd.rb +1 -12
- data/lib/nokogiri/xml/element_decl.rb +1 -1
- data/lib/nokogiri/xml/entity_decl.rb +1 -1
- data/lib/nokogiri/xml/node.rb +75 -172
- data/lib/nokogiri/xml/node/save_options.rb +0 -10
- data/lib/nokogiri/xml/node_set.rb +3 -28
- data/lib/nokogiri/xml/parse_options.rb +0 -8
- data/lib/nokogiri/xml/reader.rb +6 -44
- data/lib/nokogiri/xml/sax/document.rb +5 -9
- data/lib/nokogiri/xml/schema.rb +1 -7
- data/lib/nokogiri/xslt.rb +5 -9
- data/lib/xercesImpl.jar +0 -0
- data/tasks/cross_compile.rb +12 -27
- data/tasks/test.rb +0 -0
- data/test/css/test_parser.rb +19 -40
- data/test/css/test_tokenizer.rb +0 -8
- data/test/helper.rb +1 -4
- data/test/html/sax/test_parser.rb +21 -47
- data/test/html/sax/test_parser_context.rb +2 -2
- data/test/html/test_document.rb +3 -58
- data/test/html/test_document_encoding.rb +0 -53
- data/test/html/test_document_fragment.rb +13 -82
- data/test/html/test_element_description.rb +4 -2
- data/test/html/test_node.rb +0 -9
- data/test/test_memory_leak.rb +2 -57
- data/test/test_nokogiri.rb +14 -20
- data/test/test_reader.rb +7 -47
- data/test/test_xslt_transforms.rb +5 -8
- data/test/xml/sax/test_parser.rb +17 -34
- data/test/xml/sax/test_parser_context.rb +0 -50
- data/test/xml/sax/test_push_parser.rb +1 -18
- data/test/xml/test_attr.rb +4 -31
- data/test/xml/test_attribute_decl.rb +7 -3
- data/test/xml/test_builder.rb +5 -5
- data/test/xml/test_cdata.rb +3 -3
- data/test/xml/test_document.rb +18 -15
- data/test/xml/test_document_fragment.rb +20 -19
- data/test/xml/test_dtd.rb +13 -18
- 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 +15 -54
- data/test/xml/test_node_reparenting.rb +42 -85
- data/test/xml/test_node_set.rb +2 -61
- data/test/xml/test_schema.rb +0 -5
- data/test/xml/test_text.rb +2 -11
- data/test/xml/test_unparented_node.rb +1 -1
- data/test/xml/test_xpath.rb +7 -43
- metadata +442 -473
- metadata.gz.sig +0 -0
- data/.gemtest +0 -0
- data/ext/nokogiri/depend +0 -358
- data/ext/nokogiri/libcharset-1.dll +0 -0
- data/ext/nokogiri/libexslt.dll +0 -0
- data/ext/nokogiri/libiconv-2.dll +0 -0
- data/ext/nokogiri/libxml2.dll +0 -0
- data/ext/nokogiri/libxslt.dll +0 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/zlib1.dll +0 -0
- data/lib/nokogiri/css/parser_extras.rb +0 -91
- 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/test/decorators/test_slop.rb +0 -16
- data/test/ffi/test_document.rb +0 -35
- data/test/files/encoding.html +0 -82
- data/test/files/encoding.xhtml +0 -84
- data/test/xslt/test_custom_functions.rb +0 -94
data/bin/nokogiri
CHANGED
@@ -7,7 +7,6 @@ require 'rubygems'
|
|
7
7
|
require 'nokogiri'
|
8
8
|
|
9
9
|
parse_class = Nokogiri
|
10
|
-
encoding = nil
|
11
10
|
|
12
11
|
opts = OptionParser.new do |opts|
|
13
12
|
opts.banner = "Nokogiri: an HTML, XML, SAX, and Reader parser"
|
@@ -23,10 +22,6 @@ opts = OptionParser.new do |opts|
|
|
23
22
|
parse_class = {:xml => Nokogiri::XML, :html => Nokogiri::HTML}[v]
|
24
23
|
end
|
25
24
|
|
26
|
-
opts.on("-E", "--encoding encoding", "Read as encoding (default #{encoding})") do |v|
|
27
|
-
encoding = v
|
28
|
-
end
|
29
|
-
|
30
25
|
opts.on_tail("-?", "--help", "Show this message") do
|
31
26
|
puts opts
|
32
27
|
exit
|
@@ -47,7 +42,7 @@ if uri.to_s.strip.empty?
|
|
47
42
|
exit 1
|
48
43
|
end
|
49
44
|
|
50
|
-
@doc = parse_class.parse(open(uri).read
|
45
|
+
@doc = parse_class.parse(open(uri).read)
|
51
46
|
|
52
47
|
puts "Your document is stored in @doc..."
|
53
48
|
IRB.start
|
data/deps.rip
ADDED
data/ext/nokogiri/extconf.rb
CHANGED
@@ -17,7 +17,7 @@ end
|
|
17
17
|
$CFLAGS << " #{ENV["CFLAGS"]}"
|
18
18
|
$LIBS << " #{ENV["LIBS"]}"
|
19
19
|
|
20
|
-
if Config::CONFIG['target_os'] == 'mingw32'
|
20
|
+
if Config::CONFIG['target_os'] == 'mingw32'
|
21
21
|
$CFLAGS << " -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF"
|
22
22
|
elsif Config::CONFIG['target_os'] =~ /solaris/
|
23
23
|
$CFLAGS << " -DUSE_INCLUDED_VASPRINTF"
|
@@ -29,79 +29,58 @@ if RbConfig::MAKEFILE_CONFIG['CC'] =~ /mingw/
|
|
29
29
|
$CFLAGS << " -DIN_LIBXML"
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
$CFLAGS << " -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
|
34
|
-
end
|
35
|
-
|
36
|
-
if Config::CONFIG['target_os'] =~ /mswin32/
|
37
|
-
lib_prefix = 'lib'
|
38
|
-
|
39
|
-
# There's no default include/lib dir on Windows. Let's just add the Ruby ones
|
40
|
-
# and resort on the search path specified by INCLUDE and LIB environment
|
41
|
-
# variables
|
42
|
-
HEADER_DIRS = [INCLUDEDIR]
|
43
|
-
LIB_DIRS = [LIBDIR]
|
44
|
-
XML2_HEADER_DIRS = [File.join(INCLUDEDIR, "libxml2"), INCLUDEDIR]
|
45
|
-
|
46
|
-
else
|
47
|
-
lib_prefix = ''
|
48
|
-
|
49
|
-
HEADER_DIRS = [
|
50
|
-
# First search /opt/local for macports
|
51
|
-
'/opt/local/include',
|
32
|
+
$CFLAGS << " -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
|
52
33
|
|
53
|
-
|
54
|
-
|
34
|
+
HEADER_DIRS = [
|
35
|
+
# First search /opt/local for macports
|
36
|
+
'/opt/local/include',
|
55
37
|
|
56
|
-
|
57
|
-
|
38
|
+
# Then search /usr/local for people that installed from source
|
39
|
+
'/usr/local/include',
|
58
40
|
|
59
|
-
|
60
|
-
|
61
|
-
'/usr/include/libxml2',
|
62
|
-
]
|
41
|
+
# Check the ruby install locations
|
42
|
+
INCLUDEDIR,
|
63
43
|
|
64
|
-
|
65
|
-
|
66
|
-
|
44
|
+
# Finally fall back to /usr
|
45
|
+
'/usr/include',
|
46
|
+
'/usr/include/libxml2',
|
47
|
+
]
|
67
48
|
|
68
|
-
|
69
|
-
|
49
|
+
LIB_DIRS = [
|
50
|
+
# First search /opt/local for macports
|
51
|
+
'/opt/local/lib',
|
70
52
|
|
71
|
-
|
72
|
-
|
53
|
+
# Then search /usr/local for people that installed from source
|
54
|
+
'/usr/local/lib',
|
73
55
|
|
74
|
-
|
75
|
-
|
76
|
-
]
|
56
|
+
# Check the ruby install locations
|
57
|
+
LIBDIR,
|
77
58
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
File.join(INCLUDEDIR, "libxml2")
|
82
|
-
] + HEADER_DIRS
|
83
|
-
end
|
59
|
+
# Finally fall back to /usr
|
60
|
+
'/usr/lib',
|
61
|
+
]
|
84
62
|
|
85
63
|
dir_config('zlib', HEADER_DIRS, LIB_DIRS)
|
86
64
|
dir_config('iconv', HEADER_DIRS, LIB_DIRS)
|
87
|
-
dir_config('xml2',
|
65
|
+
dir_config('xml2', [
|
66
|
+
'/opt/local/include/libxml2',
|
67
|
+
'/usr/local/include/libxml2',
|
68
|
+
File.join(INCLUDEDIR, "libxml2")] + HEADER_DIRS, LIB_DIRS)
|
88
69
|
dir_config('xslt', HEADER_DIRS, LIB_DIRS)
|
89
70
|
|
90
71
|
def asplode(lib)
|
91
72
|
abort "-----\n#{lib} is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.\n-----"
|
92
73
|
end
|
93
74
|
|
94
|
-
|
95
|
-
|
75
|
+
asplode "iconv" unless find_header('iconv.h')
|
96
76
|
asplode "libxml2" unless find_header('libxml/parser.h')
|
97
77
|
asplode "libxslt" unless find_header('libxslt/xslt.h')
|
98
78
|
asplode "libexslt" unless find_header('libexslt/exslt.h')
|
99
|
-
asplode "
|
100
|
-
asplode "libxml2" unless find_library(
|
101
|
-
asplode "libxslt" unless find_library(
|
102
|
-
asplode "libexslt" unless find_library(
|
79
|
+
asplode "zlib" unless find_library('z', 'gzopen')
|
80
|
+
asplode "libxml2" unless find_library('xml2', 'xmlParseDoc')
|
81
|
+
asplode "libxslt" unless find_library('xslt', 'xsltParseStylesheetDoc')
|
82
|
+
asplode "libexslt" unless find_library('exslt', 'exsltFuncRegister')
|
103
83
|
|
104
|
-
have_func 'xmlFirstElementChild'
|
105
84
|
have_func('xmlRelaxNGSetParserStructuredErrors')
|
106
85
|
have_func('xmlRelaxNGSetParserStructuredErrors')
|
107
86
|
have_func('xmlRelaxNGSetValidStructuredErrors')
|
data/ext/nokogiri/nokogiri.c
CHANGED
@@ -30,14 +30,12 @@ int is_2_6_16(void)
|
|
30
30
|
|
31
31
|
void Init_nokogiri()
|
32
32
|
{
|
33
|
-
#ifndef __MACRUBY__
|
34
33
|
xmlMemSetup(
|
35
34
|
(xmlFreeFunc)ruby_xfree,
|
36
35
|
(xmlMallocFunc)ruby_xmalloc,
|
37
36
|
(xmlReallocFunc)ruby_xrealloc,
|
38
37
|
strdup
|
39
38
|
);
|
40
|
-
#endif
|
41
39
|
|
42
40
|
mNokogiri = rb_define_module("Nokogiri");
|
43
41
|
mNokogiriXml = rb_define_module_under(mNokogiri, "XML");
|
data/ext/nokogiri/nokogiri.h
CHANGED
@@ -27,7 +27,6 @@ int vasprintf (char **strp, const char *fmt, va_list ap);
|
|
27
27
|
#include <libxml/HTMLparser.h>
|
28
28
|
#include <libxml/HTMLtree.h>
|
29
29
|
#include <libxml/relaxng.h>
|
30
|
-
#include <libxslt/extensions.h>
|
31
30
|
#include <ruby.h>
|
32
31
|
|
33
32
|
#ifdef HAVE_RUBY_ENCODING_H
|
@@ -78,8 +77,6 @@ int is_2_6_16(void) ;
|
|
78
77
|
#define RBSTR_OR_QNIL(_str) \
|
79
78
|
(_str ? NOKOGIRI_STR_NEW2(_str) : Qnil)
|
80
79
|
|
81
|
-
#include <xml_libxml2_hacks.h>
|
82
|
-
|
83
80
|
#include <xml_io.h>
|
84
81
|
#include <xml_document.h>
|
85
82
|
#include <html_entity_lookup.h>
|
@@ -135,8 +132,6 @@ extern VALUE mNokogiriXslt ;
|
|
135
132
|
#define NOKOGIRI_DEBUG_START(p)
|
136
133
|
#define NOKOGIRI_DEBUG_END(p)
|
137
134
|
|
138
|
-
#endif
|
139
|
-
|
140
135
|
#ifndef RSTRING_PTR
|
141
136
|
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
142
137
|
#endif
|
@@ -153,10 +148,6 @@ extern VALUE mNokogiriXslt ;
|
|
153
148
|
#define RARRAY_LEN(a) RARRAY(a)->len
|
154
149
|
#endif
|
155
150
|
|
156
|
-
#ifndef __builtin_expect
|
157
|
-
# if defined(__GNUC__)
|
158
|
-
# define __builtin_expect(expr, c) __builtin_expect((long)(expr), (long)(c))
|
159
|
-
# endif
|
160
151
|
#endif
|
161
152
|
|
162
153
|
#endif
|
data/ext/nokogiri/xml_document.c
CHANGED
@@ -41,25 +41,11 @@ static void dealloc(xmlDocPtr doc)
|
|
41
41
|
static void recursively_remove_namespaces_from_node(xmlNodePtr node)
|
42
42
|
{
|
43
43
|
xmlNodePtr child ;
|
44
|
-
xmlAttrPtr property ;
|
45
44
|
|
46
45
|
xmlSetNs(node, NULL);
|
47
46
|
|
48
47
|
for (child = node->children ; child ; child = child->next)
|
49
48
|
recursively_remove_namespaces_from_node(child);
|
50
|
-
|
51
|
-
if (node->nsDef) {
|
52
|
-
xmlFreeNsList(node->nsDef);
|
53
|
-
node->nsDef = NULL;
|
54
|
-
}
|
55
|
-
|
56
|
-
if (node->properties != NULL) {
|
57
|
-
property = node->properties ;
|
58
|
-
while (property != NULL) {
|
59
|
-
if (property->ns) property->ns = NULL ;
|
60
|
-
property = property->next ;
|
61
|
-
}
|
62
|
-
}
|
63
49
|
}
|
64
50
|
|
65
51
|
/*
|
data/ext/nokogiri/xml_dtd.c
CHANGED
@@ -84,9 +84,9 @@ static VALUE attributes(VALUE self)
|
|
84
84
|
|
85
85
|
Data_Get_Struct(self, xmlDtd, dtd);
|
86
86
|
|
87
|
-
|
87
|
+
if(!dtd->attributes) return Qnil;
|
88
88
|
|
89
|
-
|
89
|
+
hash = rb_hash_new();
|
90
90
|
|
91
91
|
xmlHashScan((xmlHashTablePtr)dtd->attributes, element_copier, (void *)hash);
|
92
92
|
|
data/ext/nokogiri/xml_io.c
CHANGED
@@ -2,47 +2,22 @@
|
|
2
2
|
|
3
3
|
static ID id_read, id_write;
|
4
4
|
|
5
|
-
VALUE read_check(VALUE *args) {
|
6
|
-
return rb_funcall(args[0], id_read, 1, args[1]);
|
7
|
-
}
|
8
|
-
|
9
|
-
VALUE read_failed(void) {
|
10
|
-
return Qnil;
|
11
|
-
}
|
12
|
-
|
13
5
|
int io_read_callback(void * ctx, char * buffer, int len) {
|
14
|
-
VALUE
|
15
|
-
|
16
|
-
|
17
|
-
args[0] = (VALUE)ctx;
|
18
|
-
args[1] = INT2NUM(len);
|
19
|
-
|
20
|
-
string = rb_rescue(read_check, (VALUE)args, read_failed, 0);
|
6
|
+
VALUE io = (VALUE)ctx;
|
7
|
+
VALUE string = rb_funcall(io, id_read, 1, INT2NUM(len));
|
21
8
|
|
22
9
|
if(NIL_P(string)) return 0;
|
23
10
|
|
24
|
-
|
25
|
-
safe_len = str_len > (size_t)len ? (size_t)len : str_len;
|
26
|
-
memcpy(buffer, StringValuePtr(string), safe_len);
|
11
|
+
memcpy(buffer, StringValuePtr(string), (unsigned int)RSTRING_LEN(string));
|
27
12
|
|
28
|
-
return
|
29
|
-
}
|
30
|
-
|
31
|
-
VALUE write_check(VALUE *args) {
|
32
|
-
return rb_funcall(args[0], id_write, 1, args[1]);
|
33
|
-
}
|
34
|
-
|
35
|
-
VALUE write_failed(void) {
|
36
|
-
return Qnil;
|
13
|
+
return (int)RSTRING_LEN(string);
|
37
14
|
}
|
38
15
|
|
39
16
|
int io_write_callback(void * ctx, char * buffer, int len) {
|
40
|
-
VALUE
|
41
|
-
|
42
|
-
args[0] = (VALUE)ctx;
|
43
|
-
args[1] = rb_str_new(buffer, (long)len);
|
17
|
+
VALUE io = (VALUE)ctx;
|
18
|
+
VALUE string = rb_str_new(buffer, len);
|
44
19
|
|
45
|
-
|
20
|
+
rb_funcall(io, id_write, 1, string);
|
46
21
|
return len;
|
47
22
|
}
|
48
23
|
|
data/ext/nokogiri/xml_node.c
CHANGED
@@ -14,7 +14,10 @@ static void debug_node_dealloc(xmlNodePtr x)
|
|
14
14
|
|
15
15
|
static void mark(xmlNodePtr node)
|
16
16
|
{
|
17
|
-
|
17
|
+
/* it's OK if the document isn't fully realized (as in XML::Reader). */
|
18
|
+
/* see http://github.com/tenderlove/nokogiri/issues/closed/#issue/95 */
|
19
|
+
if (DOC_RUBY_OBJECT_TEST(node->doc) && DOC_RUBY_OBJECT(node->doc))
|
20
|
+
rb_gc_mark(DOC_RUBY_OBJECT(node->doc));
|
18
21
|
}
|
19
22
|
|
20
23
|
/* :nodoc: */
|
@@ -100,7 +103,7 @@ static xmlNodePtr xmlReplaceNodeWrapper(xmlNodePtr pivot, xmlNodePtr new_node)
|
|
100
103
|
static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_reparentee_func prf)
|
101
104
|
{
|
102
105
|
VALUE reparented_obj ;
|
103
|
-
xmlNodePtr reparentee, pivot, reparented
|
106
|
+
xmlNodePtr reparentee, pivot, reparented ;
|
104
107
|
|
105
108
|
if(!rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlNode))
|
106
109
|
rb_raise(rb_eArgError, "node must be a Nokogiri::XML::Node");
|
@@ -138,34 +141,6 @@ static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_rep
|
|
138
141
|
}
|
139
142
|
}
|
140
143
|
|
141
|
-
if (reparentee->type == XML_TEXT_NODE && pivot->next && pivot->next->type == XML_TEXT_NODE) {
|
142
|
-
/*
|
143
|
-
* libxml merges text nodes in a right-to-left fashion, meaning that if
|
144
|
-
* there are two text nodes who would be adjacent, the right (or following,
|
145
|
-
* or next) node will be merged into the left (or preceding, or previous)
|
146
|
-
* node.
|
147
|
-
*
|
148
|
-
* and by "merged" I mean the string contents will be concatenated onto the
|
149
|
-
* left node's contents, and then the node will be freed.
|
150
|
-
*
|
151
|
-
* which means that if we have a ruby object wrapped around the right node,
|
152
|
-
* its memory would be freed out from under it.
|
153
|
-
*
|
154
|
-
* so, we detect this edge case and unlink-and-root the text node before it gets
|
155
|
-
* merged. then we dup the node and insert that duplicate back into the
|
156
|
-
* document where the real node was.
|
157
|
-
*
|
158
|
-
* yes, this is totally lame.
|
159
|
-
*/
|
160
|
-
next_text = pivot->next ;
|
161
|
-
new_next_text = xmlDocCopyNode(next_text, pivot->doc, 1) ;
|
162
|
-
|
163
|
-
xmlUnlinkNode(next_text);
|
164
|
-
NOKOGIRI_ROOT_NODE(next_text);
|
165
|
-
|
166
|
-
xmlAddNextSibling(pivot, new_next_text);
|
167
|
-
}
|
168
|
-
|
169
144
|
/* TODO: I really want to remove this. We shouldn't support 2.6.16 anymore */
|
170
145
|
if ( reparentee->type == XML_TEXT_NODE && pivot->type == XML_TEXT_NODE && is_2_6_16() ) {
|
171
146
|
/* work around a string-handling bug in libxml 2.6.16. we'd rather leak than segfault. */
|
@@ -248,13 +223,7 @@ static VALUE encode_special_chars(VALUE self, VALUE string)
|
|
248
223
|
* call-seq:
|
249
224
|
* create_internal_subset(name, external_id, system_id)
|
250
225
|
*
|
251
|
-
* Create
|
252
|
-
*
|
253
|
-
* doc.create_internal_subset("chapter", "-//OASIS//DTD DocBook XML//EN", "chapter.dtd")
|
254
|
-
* # => <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML//EN" "chapter.dtd">
|
255
|
-
*
|
256
|
-
* doc.create_internal_subset("chapter", nil, "chapter.dtd")
|
257
|
-
* # => <!DOCTYPE chapter SYSTEM "chapter.dtd">
|
226
|
+
* Create an internal subset
|
258
227
|
*/
|
259
228
|
static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, VALUE system_id)
|
260
229
|
{
|
@@ -380,8 +349,6 @@ static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
|
|
380
349
|
dup = xmlDocCopyNode(node, node->doc, (int)NUM2INT(level));
|
381
350
|
if(dup == NULL) return Qnil;
|
382
351
|
|
383
|
-
NOKOGIRI_ROOT_NODE(dup);
|
384
|
-
|
385
352
|
return Nokogiri_wrap_xml_node(rb_obj_class(self), dup);
|
386
353
|
}
|
387
354
|
|
@@ -779,8 +746,7 @@ static VALUE attribute_nodes(VALUE self)
|
|
779
746
|
* call-seq:
|
780
747
|
* namespace()
|
781
748
|
*
|
782
|
-
* returns the
|
783
|
-
* attribute), as a Namespace object.
|
749
|
+
* returns the Nokogiri::XML::Namespace for the node, if one exists.
|
784
750
|
*/
|
785
751
|
static VALUE namespace(VALUE self)
|
786
752
|
{
|
@@ -797,7 +763,7 @@ static VALUE namespace(VALUE self)
|
|
797
763
|
* call-seq:
|
798
764
|
* namespace_definitions()
|
799
765
|
*
|
800
|
-
* returns
|
766
|
+
* returns a list of Namespace nodes defined on _self_
|
801
767
|
*/
|
802
768
|
static VALUE namespace_definitions(VALUE self)
|
803
769
|
{
|
@@ -826,10 +792,8 @@ static VALUE namespace_definitions(VALUE self)
|
|
826
792
|
* call-seq:
|
827
793
|
* namespace_scopes()
|
828
794
|
*
|
829
|
-
*
|
830
|
-
*
|
831
|
-
* namespaces ("xmlns=" style) for self are included in this array; Default
|
832
|
-
* namespaces for ancestors, however, are not. See also #namespaces
|
795
|
+
* returns a list of Namespace nodes in scope for _self_. this is all
|
796
|
+
* namespaces defined in the node, or in any ancestor node.
|
833
797
|
*/
|
834
798
|
static VALUE namespace_scopes(VALUE self)
|
835
799
|
{
|
@@ -1053,41 +1017,30 @@ static VALUE line(VALUE self)
|
|
1053
1017
|
* call-seq:
|
1054
1018
|
* add_namespace_definition(prefix, href)
|
1055
1019
|
*
|
1056
|
-
* Adds a namespace definition with +prefix+ using +href+
|
1057
|
-
* as if parsed XML for this node had included an attribute
|
1058
|
-
* 'xmlns:prefix=value'. A default namespace for this node ("xmlns=") can be
|
1059
|
-
* added by passing 'nil' for prefix. Namespaces added this way will not
|
1060
|
-
* show up in #attributes, but they will be included as an xmlns attribute
|
1061
|
-
* when the node is serialized to XML.
|
1020
|
+
* Adds a namespace definition with +prefix+ using +href+
|
1062
1021
|
*/
|
1063
1022
|
static VALUE add_namespace_definition(VALUE self, VALUE prefix, VALUE href)
|
1064
1023
|
{
|
1065
|
-
xmlNodePtr node
|
1024
|
+
xmlNodePtr node;
|
1066
1025
|
xmlNsPtr ns;
|
1067
1026
|
|
1068
1027
|
Data_Get_Struct(self, xmlNode, node);
|
1069
|
-
namespacee = node ;
|
1070
1028
|
|
1071
|
-
ns =
|
1072
|
-
node->doc,
|
1029
|
+
ns = xmlNewNs(
|
1073
1030
|
node,
|
1031
|
+
(const xmlChar *)StringValuePtr(href),
|
1074
1032
|
(const xmlChar *)(NIL_P(prefix) ? NULL : StringValuePtr(prefix))
|
1075
1033
|
);
|
1076
1034
|
|
1077
1035
|
if(!ns) {
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
ns = xmlNewNs(
|
1082
|
-
namespacee,
|
1083
|
-
(const xmlChar *)StringValuePtr(href),
|
1036
|
+
ns = xmlSearchNs(
|
1037
|
+
node->doc,
|
1038
|
+
node,
|
1084
1039
|
(const xmlChar *)(NIL_P(prefix) ? NULL : StringValuePtr(prefix))
|
1085
1040
|
);
|
1086
1041
|
}
|
1087
1042
|
|
1088
|
-
if (
|
1089
|
-
|
1090
|
-
if(NIL_P(prefix) || node != namespacee) xmlSetNs(node, ns);
|
1043
|
+
if(NIL_P(prefix)) xmlSetNs(node, ns);
|
1091
1044
|
|
1092
1045
|
return Nokogiri_wrap_xml_namespace(node->doc, ns);
|
1093
1046
|
}
|
@@ -1168,13 +1121,14 @@ static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
|
|
1168
1121
|
{
|
1169
1122
|
xmlNodePtr node;
|
1170
1123
|
xmlNodePtr list;
|
1171
|
-
xmlNodePtr child_iter;
|
1172
1124
|
xmlNodeSetPtr set;
|
1173
|
-
xmlParserErrors error;
|
1174
1125
|
VALUE doc, err;
|
1175
1126
|
|
1176
1127
|
Data_Get_Struct(self, xmlNode, node);
|
1177
1128
|
|
1129
|
+
if(!node->parent)
|
1130
|
+
rb_raise(rb_eRuntimeError, "no contextual parsing on unlinked nodes");
|
1131
|
+
|
1178
1132
|
doc = DOC_RUBY_OBJECT(node->doc);
|
1179
1133
|
err = rb_iv_get(doc, "@errors");
|
1180
1134
|
|
@@ -1187,41 +1141,19 @@ static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
|
|
1187
1141
|
htmlHandleOmittedElem(0);
|
1188
1142
|
#endif
|
1189
1143
|
|
1190
|
-
|
1144
|
+
xmlParseInNodeContext(
|
1191
1145
|
node,
|
1192
1146
|
StringValuePtr(_str),
|
1193
1147
|
(int)RSTRING_LEN(_str),
|
1194
1148
|
(int)NUM2INT(_options),
|
1195
1149
|
&list);
|
1196
1150
|
|
1197
|
-
/* make sure parent/child pointers are coherent so an unlink will work properly (#331) */
|
1198
|
-
child_iter = node->doc->children ;
|
1199
|
-
while (child_iter) {
|
1200
|
-
if (child_iter->parent != (xmlNodePtr)node->doc)
|
1201
|
-
child_iter->parent = (xmlNodePtr)node->doc ;
|
1202
|
-
child_iter = child_iter->next ;
|
1203
|
-
}
|
1204
|
-
|
1205
1151
|
#ifndef HTML_PARSE_NOIMPLIED
|
1206
1152
|
htmlHandleOmittedElem(1);
|
1207
1153
|
#endif
|
1208
1154
|
|
1209
1155
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
1210
1156
|
|
1211
|
-
/* FIXME: This probably needs to handle more constants... */
|
1212
|
-
switch(error) {
|
1213
|
-
case XML_ERR_OK:
|
1214
|
-
break;
|
1215
|
-
|
1216
|
-
case XML_ERR_INTERNAL_ERROR:
|
1217
|
-
case XML_ERR_NO_MEMORY:
|
1218
|
-
rb_raise(rb_eRuntimeError, "error parsing fragment (%d)", error);
|
1219
|
-
break;
|
1220
|
-
|
1221
|
-
default:
|
1222
|
-
break;
|
1223
|
-
}
|
1224
|
-
|
1225
1157
|
set = xmlXPathNodeSetCreate(NULL);
|
1226
1158
|
|
1227
1159
|
while(list) {
|
@@ -1238,8 +1170,6 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
|
|
1238
1170
|
VALUE document = Qnil ;
|
1239
1171
|
VALUE node_cache = Qnil ;
|
1240
1172
|
VALUE rb_node = Qnil ;
|
1241
|
-
int node_has_a_document = 0 ;
|
1242
|
-
void (*mark_method)(xmlNodePtr) = NULL ;
|
1243
1173
|
|
1244
1174
|
assert(node);
|
1245
1175
|
|
@@ -1248,9 +1178,11 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
|
|
1248
1178
|
|
1249
1179
|
if(NULL != node->_private) return (VALUE)node->_private;
|
1250
1180
|
|
1251
|
-
if(
|
1252
|
-
|
1253
|
-
|
1181
|
+
if(RTEST(klass))
|
1182
|
+
rb_node = Data_Wrap_Struct(klass, mark, debug_node_dealloc, node) ;
|
1183
|
+
|
1184
|
+
else switch(node->type)
|
1185
|
+
{
|
1254
1186
|
case XML_ELEMENT_NODE:
|
1255
1187
|
klass = cNokogiriXmlElement;
|
1256
1188
|
break;
|
@@ -1289,19 +1221,15 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
|
|
1289
1221
|
break;
|
1290
1222
|
default:
|
1291
1223
|
klass = cNokogiriXmlNode;
|
1292
|
-
}
|
1293
1224
|
}
|
1294
1225
|
|
1295
|
-
|
1296
|
-
/* see https://github.com/tenderlove/nokogiri/issues/95 */
|
1297
|
-
/* and https://github.com/tenderlove/nokogiri/issues/439 */
|
1298
|
-
node_has_a_document = (DOC_RUBY_OBJECT_TEST(node->doc) && DOC_RUBY_OBJECT(node->doc)) ? 1 : 0 ;
|
1299
|
-
mark_method = node_has_a_document ? mark : NULL ;
|
1226
|
+
rb_node = Data_Wrap_Struct(klass, mark, debug_node_dealloc, node) ;
|
1300
1227
|
|
1301
|
-
rb_node = Data_Wrap_Struct(klass, mark_method, debug_node_dealloc, node) ;
|
1302
1228
|
node->_private = (void *)rb_node;
|
1303
1229
|
|
1304
|
-
if (
|
1230
|
+
if (DOC_RUBY_OBJECT_TEST(node->doc) && DOC_RUBY_OBJECT(node->doc)) {
|
1231
|
+
/* it's OK if the document isn't fully realized (as in XML::Reader). */
|
1232
|
+
/* see http://github.com/tenderlove/nokogiri/issues/closed/#issue/95 */
|
1305
1233
|
document = DOC_RUBY_OBJECT(node->doc);
|
1306
1234
|
node_cache = DOC_NODE_CACHE(node->doc);
|
1307
1235
|
rb_ary_push(node_cache, rb_node);
|