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.

Files changed (178) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG.ja.rdoc +8 -83
  3. data/CHANGELOG.rdoc +6 -80
  4. data/Manifest.txt +4 -74
  5. data/README.ja.rdoc +5 -1
  6. data/README.rdoc +8 -22
  7. data/Rakefile +79 -60
  8. data/bin/nokogiri +1 -6
  9. data/deps.rip +5 -0
  10. data/ext/nokogiri/extconf.rb +32 -53
  11. data/ext/nokogiri/nokogiri.c +0 -2
  12. data/ext/nokogiri/nokogiri.h +0 -9
  13. data/ext/nokogiri/xml_document.c +0 -14
  14. data/ext/nokogiri/xml_dtd.c +2 -2
  15. data/ext/nokogiri/xml_io.c +7 -32
  16. data/ext/nokogiri/xml_node.c +31 -103
  17. data/ext/nokogiri/xml_node_set.c +8 -8
  18. data/ext/nokogiri/xml_reader.c +1 -20
  19. data/ext/nokogiri/xml_sax_parser.c +3 -5
  20. data/ext/nokogiri/xml_sax_parser_context.c +0 -40
  21. data/ext/nokogiri/xml_xpath_context.c +2 -35
  22. data/ext/nokogiri/xslt_stylesheet.c +6 -124
  23. data/lib/isorelax.jar +0 -0
  24. data/lib/jing.jar +0 -0
  25. data/lib/nekodtd.jar +0 -0
  26. data/lib/nekohtml.jar +0 -0
  27. data/lib/nokogiri.rb +7 -3
  28. data/lib/nokogiri/css.rb +3 -6
  29. data/lib/nokogiri/css/generated_parser.rb +669 -0
  30. data/lib/nokogiri/css/generated_tokenizer.rb +145 -0
  31. data/lib/nokogiri/css/parser.rb +70 -665
  32. data/lib/nokogiri/css/parser.y +1 -6
  33. data/lib/nokogiri/css/tokenizer.rb +3 -148
  34. data/lib/nokogiri/css/tokenizer.rex +1 -1
  35. data/lib/nokogiri/css/xpath_visitor.rb +14 -16
  36. data/lib/nokogiri/decorators/slop.rb +3 -5
  37. data/lib/nokogiri/html.rb +3 -2
  38. data/lib/nokogiri/html/document.rb +18 -134
  39. data/lib/nokogiri/html/document_fragment.rb +21 -26
  40. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  41. data/lib/nokogiri/html/sax/parser.rb +2 -6
  42. data/lib/nokogiri/nokogiri.jar +0 -0
  43. data/lib/nokogiri/version.rb +4 -9
  44. data/lib/nokogiri/xml/attribute_decl.rb +1 -1
  45. data/lib/nokogiri/xml/builder.rb +1 -1
  46. data/lib/nokogiri/xml/document.rb +3 -27
  47. data/lib/nokogiri/xml/document_fragment.rb +2 -9
  48. data/lib/nokogiri/xml/dtd.rb +1 -12
  49. data/lib/nokogiri/xml/element_decl.rb +1 -1
  50. data/lib/nokogiri/xml/entity_decl.rb +1 -1
  51. data/lib/nokogiri/xml/node.rb +75 -172
  52. data/lib/nokogiri/xml/node/save_options.rb +0 -10
  53. data/lib/nokogiri/xml/node_set.rb +3 -28
  54. data/lib/nokogiri/xml/parse_options.rb +0 -8
  55. data/lib/nokogiri/xml/reader.rb +6 -44
  56. data/lib/nokogiri/xml/sax/document.rb +5 -9
  57. data/lib/nokogiri/xml/schema.rb +1 -7
  58. data/lib/nokogiri/xslt.rb +5 -9
  59. data/lib/xercesImpl.jar +0 -0
  60. data/tasks/cross_compile.rb +12 -27
  61. data/tasks/test.rb +0 -0
  62. data/test/css/test_parser.rb +19 -40
  63. data/test/css/test_tokenizer.rb +0 -8
  64. data/test/helper.rb +1 -4
  65. data/test/html/sax/test_parser.rb +21 -47
  66. data/test/html/sax/test_parser_context.rb +2 -2
  67. data/test/html/test_document.rb +3 -58
  68. data/test/html/test_document_encoding.rb +0 -53
  69. data/test/html/test_document_fragment.rb +13 -82
  70. data/test/html/test_element_description.rb +4 -2
  71. data/test/html/test_node.rb +0 -9
  72. data/test/test_memory_leak.rb +2 -57
  73. data/test/test_nokogiri.rb +14 -20
  74. data/test/test_reader.rb +7 -47
  75. data/test/test_xslt_transforms.rb +5 -8
  76. data/test/xml/sax/test_parser.rb +17 -34
  77. data/test/xml/sax/test_parser_context.rb +0 -50
  78. data/test/xml/sax/test_push_parser.rb +1 -18
  79. data/test/xml/test_attr.rb +4 -31
  80. data/test/xml/test_attribute_decl.rb +7 -3
  81. data/test/xml/test_builder.rb +5 -5
  82. data/test/xml/test_cdata.rb +3 -3
  83. data/test/xml/test_document.rb +18 -15
  84. data/test/xml/test_document_fragment.rb +20 -19
  85. data/test/xml/test_dtd.rb +13 -18
  86. data/test/xml/test_element_content.rb +1 -1
  87. data/test/xml/test_element_decl.rb +1 -1
  88. data/test/xml/test_entity_decl.rb +12 -10
  89. data/test/xml/test_namespace.rb +7 -5
  90. data/test/xml/test_node.rb +15 -54
  91. data/test/xml/test_node_reparenting.rb +42 -85
  92. data/test/xml/test_node_set.rb +2 -61
  93. data/test/xml/test_schema.rb +0 -5
  94. data/test/xml/test_text.rb +2 -11
  95. data/test/xml/test_unparented_node.rb +1 -1
  96. data/test/xml/test_xpath.rb +7 -43
  97. metadata +442 -473
  98. metadata.gz.sig +0 -0
  99. data/.gemtest +0 -0
  100. data/ext/nokogiri/depend +0 -358
  101. data/ext/nokogiri/libcharset-1.dll +0 -0
  102. data/ext/nokogiri/libexslt.dll +0 -0
  103. data/ext/nokogiri/libiconv-2.dll +0 -0
  104. data/ext/nokogiri/libxml2.dll +0 -0
  105. data/ext/nokogiri/libxslt.dll +0 -0
  106. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  107. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  108. data/ext/nokogiri/zlib1.dll +0 -0
  109. data/lib/nokogiri/css/parser_extras.rb +0 -91
  110. data/lib/nokogiri/ffi/encoding_handler.rb +0 -42
  111. data/lib/nokogiri/ffi/html/document.rb +0 -28
  112. data/lib/nokogiri/ffi/html/element_description.rb +0 -81
  113. data/lib/nokogiri/ffi/html/entity_lookup.rb +0 -16
  114. data/lib/nokogiri/ffi/html/sax/parser_context.rb +0 -38
  115. data/lib/nokogiri/ffi/io_callbacks.rb +0 -42
  116. data/lib/nokogiri/ffi/libxml.rb +0 -420
  117. data/lib/nokogiri/ffi/structs/common_node.rb +0 -38
  118. data/lib/nokogiri/ffi/structs/html_elem_desc.rb +0 -24
  119. data/lib/nokogiri/ffi/structs/html_entity_desc.rb +0 -13
  120. data/lib/nokogiri/ffi/structs/xml_alloc.rb +0 -16
  121. data/lib/nokogiri/ffi/structs/xml_attr.rb +0 -20
  122. data/lib/nokogiri/ffi/structs/xml_attribute.rb +0 -27
  123. data/lib/nokogiri/ffi/structs/xml_buffer.rb +0 -16
  124. data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +0 -11
  125. data/lib/nokogiri/ffi/structs/xml_document.rb +0 -117
  126. data/lib/nokogiri/ffi/structs/xml_dtd.rb +0 -28
  127. data/lib/nokogiri/ffi/structs/xml_element.rb +0 -26
  128. data/lib/nokogiri/ffi/structs/xml_element_content.rb +0 -17
  129. data/lib/nokogiri/ffi/structs/xml_entity.rb +0 -32
  130. data/lib/nokogiri/ffi/structs/xml_enumeration.rb +0 -12
  131. data/lib/nokogiri/ffi/structs/xml_node.rb +0 -28
  132. data/lib/nokogiri/ffi/structs/xml_node_set.rb +0 -53
  133. data/lib/nokogiri/ffi/structs/xml_notation.rb +0 -11
  134. data/lib/nokogiri/ffi/structs/xml_ns.rb +0 -15
  135. data/lib/nokogiri/ffi/structs/xml_parser_context.rb +0 -20
  136. data/lib/nokogiri/ffi/structs/xml_parser_input.rb +0 -19
  137. data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +0 -14
  138. data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +0 -51
  139. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +0 -124
  140. data/lib/nokogiri/ffi/structs/xml_schema.rb +0 -13
  141. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +0 -31
  142. data/lib/nokogiri/ffi/structs/xml_text_reader.rb +0 -12
  143. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +0 -38
  144. data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +0 -35
  145. data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +0 -20
  146. data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +0 -13
  147. data/lib/nokogiri/ffi/weak_bucket.rb +0 -40
  148. data/lib/nokogiri/ffi/xml/attr.rb +0 -41
  149. data/lib/nokogiri/ffi/xml/attribute_decl.rb +0 -27
  150. data/lib/nokogiri/ffi/xml/cdata.rb +0 -19
  151. data/lib/nokogiri/ffi/xml/comment.rb +0 -18
  152. data/lib/nokogiri/ffi/xml/document.rb +0 -174
  153. data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -21
  154. data/lib/nokogiri/ffi/xml/dtd.rb +0 -67
  155. data/lib/nokogiri/ffi/xml/element_content.rb +0 -43
  156. data/lib/nokogiri/ffi/xml/element_decl.rb +0 -19
  157. data/lib/nokogiri/ffi/xml/entity_decl.rb +0 -36
  158. data/lib/nokogiri/ffi/xml/entity_reference.rb +0 -19
  159. data/lib/nokogiri/ffi/xml/namespace.rb +0 -44
  160. data/lib/nokogiri/ffi/xml/node.rb +0 -559
  161. data/lib/nokogiri/ffi/xml/node_set.rb +0 -150
  162. data/lib/nokogiri/ffi/xml/processing_instruction.rb +0 -20
  163. data/lib/nokogiri/ffi/xml/reader.rb +0 -236
  164. data/lib/nokogiri/ffi/xml/relax_ng.rb +0 -85
  165. data/lib/nokogiri/ffi/xml/sax/parser.rb +0 -143
  166. data/lib/nokogiri/ffi/xml/sax/parser_context.rb +0 -79
  167. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +0 -51
  168. data/lib/nokogiri/ffi/xml/schema.rb +0 -109
  169. data/lib/nokogiri/ffi/xml/syntax_error.rb +0 -98
  170. data/lib/nokogiri/ffi/xml/text.rb +0 -18
  171. data/lib/nokogiri/ffi/xml/xpath.rb +0 -9
  172. data/lib/nokogiri/ffi/xml/xpath_context.rb +0 -153
  173. data/lib/nokogiri/ffi/xslt/stylesheet.rb +0 -77
  174. data/test/decorators/test_slop.rb +0 -16
  175. data/test/ffi/test_document.rb +0 -35
  176. data/test/files/encoding.html +0 -82
  177. data/test/files/encoding.xhtml +0 -84
  178. 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, nil, encoding)
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
@@ -0,0 +1,5 @@
1
+ git://github.com/luislavena/rake-compiler.git v0.6.0
2
+ git://github.com/tenderlove/rexical.git
3
+ git://github.com/jimweirich/rake.git
4
+ git://github.com/jmhodges/fakehoe.git
5
+ git://github.com/tenderlove/racc.git
@@ -17,7 +17,7 @@ end
17
17
  $CFLAGS << " #{ENV["CFLAGS"]}"
18
18
  $LIBS << " #{ENV["LIBS"]}"
19
19
 
20
- if Config::CONFIG['target_os'] == 'mingw32' || Config::CONFIG['target_os'] =~ /mswin32/
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
- if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/
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
- # Then search /usr/local for people that installed from source
54
- '/usr/local/include',
34
+ HEADER_DIRS = [
35
+ # First search /opt/local for macports
36
+ '/opt/local/include',
55
37
 
56
- # Check the ruby install locations
57
- INCLUDEDIR,
38
+ # Then search /usr/local for people that installed from source
39
+ '/usr/local/include',
58
40
 
59
- # Finally fall back to /usr
60
- '/usr/include',
61
- '/usr/include/libxml2',
62
- ]
41
+ # Check the ruby install locations
42
+ INCLUDEDIR,
63
43
 
64
- LIB_DIRS = [
65
- # First search /opt/local for macports
66
- '/opt/local/lib',
44
+ # Finally fall back to /usr
45
+ '/usr/include',
46
+ '/usr/include/libxml2',
47
+ ]
67
48
 
68
- # Then search /usr/local for people that installed from source
69
- '/usr/local/lib',
49
+ LIB_DIRS = [
50
+ # First search /opt/local for macports
51
+ '/opt/local/lib',
70
52
 
71
- # Check the ruby install locations
72
- LIBDIR,
53
+ # Then search /usr/local for people that installed from source
54
+ '/usr/local/lib',
73
55
 
74
- # Finally fall back to /usr
75
- '/usr/lib',
76
- ]
56
+ # Check the ruby install locations
57
+ LIBDIR,
77
58
 
78
- XML2_HEADER_DIRS = [
79
- '/opt/local/include/libxml2',
80
- '/usr/local/include/libxml2',
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', XML2_HEADER_DIRS, LIB_DIRS)
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
- pkg_config('libxslt') if RUBY_PLATFORM =~ /mingw/
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 "libiconv" unless have_func('iconv_open', 'iconv.h') or have_library('iconv', 'iconv_open', 'iconv.h')
100
- asplode "libxml2" unless find_library("#{lib_prefix}xml2", 'xmlParseDoc')
101
- asplode "libxslt" unless find_library("#{lib_prefix}xslt", 'xsltParseStylesheetDoc')
102
- asplode "libexslt" unless find_library("#{lib_prefix}exslt", 'exsltFuncRegister')
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')
@@ -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");
@@ -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
@@ -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
  /*
@@ -84,9 +84,9 @@ static VALUE attributes(VALUE self)
84
84
 
85
85
  Data_Get_Struct(self, xmlDtd, dtd);
86
86
 
87
- hash = rb_hash_new();
87
+ if(!dtd->attributes) return Qnil;
88
88
 
89
- if(!dtd->attributes) return hash;
89
+ hash = rb_hash_new();
90
90
 
91
91
  xmlHashScan((xmlHashTablePtr)dtd->attributes, element_copier, (void *)hash);
92
92
 
@@ -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 string, args[2];
15
- size_t str_len, safe_len;
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
- str_len = (size_t)RSTRING_LEN(string);
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 safe_len;
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 args[2];
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
- rb_rescue(write_check, (VALUE)args, write_failed, 0);
20
+ rb_funcall(io, id_write, 1, string);
46
21
  return len;
47
22
  }
48
23
 
@@ -14,7 +14,10 @@ static void debug_node_dealloc(xmlNodePtr x)
14
14
 
15
15
  static void mark(xmlNodePtr node)
16
16
  {
17
- rb_gc_mark(DOC_RUBY_OBJECT(node->doc));
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, next_text, new_next_text ;
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 the internal subset of a document.
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 default namespace set on this node (as with an "xmlns="
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 namespaces defined on self element directly, as an array of Namespace objects. Includes both a default namespace (as in"xmlns="), and prefixed namespaces (as in "xmlns:prefix=").
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
- * returns namespaces in scope for self -- those defined on self element
830
- * directly or any ancestor node -- as an array of Namespace objects. Default
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+ value. The result is
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, namespacee;
1024
+ xmlNodePtr node;
1066
1025
  xmlNsPtr ns;
1067
1026
 
1068
1027
  Data_Get_Struct(self, xmlNode, node);
1069
- namespacee = node ;
1070
1028
 
1071
- ns = xmlSearchNs(
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
- if (node->type != XML_ELEMENT_NODE) {
1079
- namespacee = node->parent;
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 (!ns) return Qnil ;
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
- error = xmlParseInNodeContext(
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(!RTEST(klass)) {
1252
- switch(node->type)
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
- /* It's OK if the node doesn't have a fully-realized document (as in XML::Reader). */
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 (node_has_a_document) {
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);