nokogiri 1.6.7.2-java → 1.6.8-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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/.cross_rubies +2 -0
  3. data/.travis.yml +19 -9
  4. data/CHANGELOG.rdoc +73 -5
  5. data/CONTRIBUTING.md +42 -0
  6. data/Gemfile +10 -9
  7. data/LICENSE.txt +1 -1
  8. data/Manifest.txt +7 -2
  9. data/README.md +23 -27
  10. data/ROADMAP.md +11 -1
  11. data/Rakefile +36 -17
  12. data/bin/nokogiri +2 -2
  13. data/dependencies.yml +29 -4
  14. data/ext/java/nokogiri/HtmlElementDescription.java +5 -2
  15. data/ext/java/nokogiri/NokogiriService.java +19 -0
  16. data/ext/java/nokogiri/XmlAttr.java +3 -1
  17. data/ext/java/nokogiri/XmlDocumentFragment.java +0 -14
  18. data/ext/java/nokogiri/XmlNode.java +106 -63
  19. data/ext/java/nokogiri/XmlXpathContext.java +12 -12
  20. data/ext/java/nokogiri/XsltStylesheet.java +11 -4
  21. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +8 -1
  22. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +1 -2
  23. data/ext/java/nokogiri/internals/NokogiriHelpers.java +7 -7
  24. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +1 -1
  25. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +0 -1
  26. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +3 -3
  27. data/ext/java/nokogiri/internals/ParserContext.java +4 -0
  28. data/ext/java/nokogiri/internals/SaveContextVisitor.java +18 -13
  29. data/ext/nokogiri/extconf.rb +163 -79
  30. data/ext/nokogiri/html_document.c +6 -6
  31. data/ext/nokogiri/html_element_description.c +1 -1
  32. data/ext/nokogiri/html_entity_lookup.c +1 -1
  33. data/ext/nokogiri/html_sax_parser_context.c +4 -4
  34. data/ext/nokogiri/html_sax_push_parser.c +2 -2
  35. data/ext/nokogiri/nokogiri.c +0 -7
  36. data/ext/nokogiri/nokogiri.h +1 -34
  37. data/ext/nokogiri/xml_attr.c +2 -2
  38. data/ext/nokogiri/xml_comment.c +1 -1
  39. data/ext/nokogiri/xml_document.c +20 -22
  40. data/ext/nokogiri/xml_encoding_handler.c +3 -3
  41. data/ext/nokogiri/xml_entity_reference.c +1 -1
  42. data/ext/nokogiri/xml_namespace.c +56 -17
  43. data/ext/nokogiri/xml_node.c +73 -67
  44. data/ext/nokogiri/xml_node_set.c +164 -146
  45. data/ext/nokogiri/xml_node_set.h +3 -4
  46. data/ext/nokogiri/xml_processing_instruction.c +2 -2
  47. data/ext/nokogiri/xml_reader.c +5 -18
  48. data/ext/nokogiri/xml_sax_parser.c +9 -12
  49. data/ext/nokogiri/xml_sax_parser_context.c +1 -1
  50. data/ext/nokogiri/xml_sax_push_parser.c +1 -1
  51. data/ext/nokogiri/xml_schema.c +1 -1
  52. data/ext/nokogiri/xml_syntax_error.c +0 -4
  53. data/ext/nokogiri/xml_syntax_error.h +0 -1
  54. data/ext/nokogiri/xml_text.c +1 -1
  55. data/ext/nokogiri/xml_xpath_context.c +15 -24
  56. data/ext/nokogiri/xslt_stylesheet.c +6 -6
  57. data/lib/nekohtml.jar +0 -0
  58. data/lib/nokogiri.rb +14 -7
  59. data/lib/nokogiri/css/parser.rb +8 -2
  60. data/lib/nokogiri/css/parser.y +7 -2
  61. data/lib/nokogiri/html/document.rb +4 -2
  62. data/lib/nokogiri/nokogiri.jar +0 -0
  63. data/lib/nokogiri/version.rb +1 -1
  64. data/lib/nokogiri/xml/document.rb +7 -1
  65. data/lib/nokogiri/xml/dtd.rb +4 -4
  66. data/lib/nokogiri/xml/node.rb +6 -10
  67. data/lib/nokogiri/xml/node_set.rb +3 -3
  68. data/lib/nokogiri/xml/parse_options.rb +22 -0
  69. data/lib/serializer.jar +0 -0
  70. data/lib/xalan.jar +0 -0
  71. data/lib/xercesImpl.jar +0 -0
  72. data/lib/xml-apis.jar +0 -0
  73. data/tasks/test.rb +5 -0
  74. data/test/css/test_parser.rb +7 -1
  75. data/test/files/GH_1042.html +18 -0
  76. data/test/files/namespace_pressure_test.xml +1684 -0
  77. data/test/files/tlm.html +2 -1
  78. data/test/helper.rb +4 -0
  79. data/test/html/sax/test_parser.rb +2 -2
  80. data/test/html/test_document.rb +47 -11
  81. data/test/html/test_document_encoding.rb +55 -58
  82. data/test/html/test_document_fragment.rb +27 -23
  83. data/test/html/test_node.rb +16 -0
  84. data/test/html/test_node_encoding.rb +71 -13
  85. data/test/namespaces/test_namespaces_in_parsed_doc.rb +14 -0
  86. data/test/test_css_cache.rb +1 -1
  87. data/test/test_encoding_handler.rb +2 -0
  88. data/test/test_xslt_transforms.rb +38 -3
  89. data/test/xml/sax/test_parser.rb +54 -53
  90. data/test/xml/test_document.rb +7 -2
  91. data/test/xml/test_document_encoding.rb +19 -16
  92. data/test/xml/test_document_fragment.rb +12 -0
  93. data/test/xml/test_dtd_encoding.rb +0 -2
  94. data/test/xml/test_namespace.rb +2 -2
  95. data/test/xml/test_node.rb +15 -4
  96. data/test/xml/test_node_attributes.rb +6 -0
  97. data/test/xml/test_node_encoding.rb +49 -87
  98. data/test/xml/test_node_reparenting.rb +193 -18
  99. data/test/xml/test_node_set.rb +1 -1
  100. data/test/xml/test_reader.rb +589 -0
  101. data/test/xml/test_reader_encoding.rb +100 -102
  102. data/test/xml/test_unparented_node.rb +14 -1
  103. data/test/xslt/test_exception_handling.rb +1 -1
  104. data/test_all +47 -33
  105. metadata +38 -36
  106. data/CHANGELOG.ja.rdoc +0 -1057
  107. data/test/test_reader.rb +0 -558
@@ -18,8 +18,8 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
18
18
  external_id = rb_ary_entry(rest, (long)1);
19
19
 
20
20
  doc = htmlNewDoc(
21
- RTEST(uri) ? (const xmlChar *)StringValuePtr(uri) : NULL,
22
- RTEST(external_id) ? (const xmlChar *)StringValuePtr(external_id) : NULL
21
+ RTEST(uri) ? (const xmlChar *)StringValueCStr(uri) : NULL,
22
+ RTEST(external_id) ? (const xmlChar *)StringValueCStr(external_id) : NULL
23
23
  );
24
24
  rb_doc = Nokogiri_wrap_xml_document(klass, doc);
25
25
  rb_obj_call_init(rb_doc, argc, argv);
@@ -39,8 +39,8 @@ static VALUE read_io( VALUE klass,
39
39
  VALUE encoding,
40
40
  VALUE options )
41
41
  {
42
- const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url);
43
- const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding);
42
+ const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
43
+ const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
44
44
  VALUE error_list = rb_ary_new();
45
45
  VALUE document;
46
46
  htmlDocPtr doc;
@@ -103,8 +103,8 @@ static VALUE read_memory( VALUE klass,
103
103
  VALUE options )
104
104
  {
105
105
  const char * c_buffer = StringValuePtr(string);
106
- const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url);
107
- const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding);
106
+ const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
107
+ const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
108
108
  int len = (int)RSTRING_LEN(string);
109
109
  VALUE error_list = rb_ary_new();
110
110
  VALUE document;
@@ -245,7 +245,7 @@ static VALUE name(VALUE self)
245
245
  static VALUE get_description(VALUE klass, VALUE tag_name)
246
246
  {
247
247
  const htmlElemDesc * description = htmlTagLookup(
248
- (const xmlChar *)StringValuePtr(tag_name)
248
+ (const xmlChar *)StringValueCStr(tag_name)
249
249
  );
250
250
 
251
251
  if(NULL == description) return Qnil;
@@ -9,7 +9,7 @@
9
9
  static VALUE get(VALUE self, VALUE key)
10
10
  {
11
11
  const htmlEntityDesc * desc =
12
- htmlEntityLookup((const xmlChar *)StringValuePtr(key));
12
+ htmlEntityLookup((const xmlChar *)StringValueCStr(key));
13
13
  VALUE klass, args[3];
14
14
 
15
15
  if(NULL == desc) return Qnil;
@@ -31,12 +31,12 @@ parse_memory(VALUE klass, VALUE data, VALUE encoding)
31
31
  }
32
32
 
33
33
  if (RTEST(encoding)) {
34
- xmlCharEncodingHandlerPtr enc = xmlFindCharEncodingHandler(StringValuePtr(encoding));
34
+ xmlCharEncodingHandlerPtr enc = xmlFindCharEncodingHandler(StringValueCStr(encoding));
35
35
  if (enc != NULL) {
36
36
  xmlSwitchToEncoding(ctxt, enc);
37
37
  if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
38
38
  rb_raise(rb_eRuntimeError, "Unsupported encoding %s",
39
- StringValuePtr(encoding));
39
+ StringValueCStr(encoding));
40
40
  }
41
41
  }
42
42
  }
@@ -47,8 +47,8 @@ parse_memory(VALUE klass, VALUE data, VALUE encoding)
47
47
  static VALUE parse_file(VALUE klass, VALUE filename, VALUE encoding)
48
48
  {
49
49
  htmlParserCtxtPtr ctxt = htmlCreateFileParserCtxt(
50
- StringValuePtr(filename),
51
- StringValuePtr(encoding)
50
+ StringValueCStr(filename),
51
+ StringValueCStr(encoding)
52
52
  );
53
53
  return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
54
54
  }
@@ -46,10 +46,10 @@ static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename,
46
46
 
47
47
  Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
48
48
 
49
- if(_filename != Qnil) filename = StringValuePtr(_filename);
49
+ if(_filename != Qnil) filename = StringValueCStr(_filename);
50
50
 
51
51
  if (!NIL_P(encoding)) {
52
- enc = xmlParseCharEncoding(StringValuePtr(encoding));
52
+ enc = xmlParseCharEncoding(StringValueCStr(encoding));
53
53
  if (enc == XML_CHAR_ENCODING_ERROR)
54
54
  rb_raise(rb_eArgError, "Unsupported Encoding");
55
55
  }
@@ -28,17 +28,10 @@ int vasprintf (char **strp, const char *fmt, va_list ap)
28
28
  }
29
29
  #endif
30
30
 
31
- #ifdef USING_SYSTEM_ALLOCATOR_LIBRARY /* Ruby Enterprise Edition with tcmalloc */
32
- void vasprintf_free (void *p)
33
- {
34
- system_free(p);
35
- }
36
- #else
37
31
  void vasprintf_free (void *p)
38
32
  {
39
33
  free(p);
40
34
  }
41
- #endif
42
35
 
43
36
  #ifdef HAVE_RUBY_UTIL_H
44
37
  #include "ruby/util.h"
@@ -31,12 +31,8 @@ int vasprintf (char **strp, const char *fmt, va_list ap);
31
31
  #include <libxslt/extensions.h>
32
32
  #include <libxml/c14n.h>
33
33
  #include <ruby.h>
34
-
35
- #ifdef HAVE_RUBY_ENCODING_H
36
34
  #include <ruby/st.h>
37
- #else
38
- #include <st.h>
39
- #endif
35
+ #include <ruby/encoding.h>
40
36
 
41
37
  #ifndef UNUSED
42
38
  # if defined(__GNUC__)
@@ -56,25 +52,12 @@ int vasprintf (char **strp, const char *fmt, va_list ap);
56
52
  # endif
57
53
  #endif
58
54
 
59
- #ifdef HAVE_RUBY_ENCODING_H
60
-
61
- #include <ruby/encoding.h>
62
-
63
55
  #define NOKOGIRI_STR_NEW2(str) \
64
56
  NOKOGIRI_STR_NEW(str, strlen((const char *)(str)))
65
57
 
66
58
  #define NOKOGIRI_STR_NEW(str, len) \
67
59
  rb_external_str_new_with_enc((const char *)(str), (long)(len), rb_utf8_encoding())
68
60
 
69
- #else
70
-
71
- #define NOKOGIRI_STR_NEW2(str) \
72
- rb_str_new2((const char *)(str))
73
-
74
- #define NOKOGIRI_STR_NEW(str, len) \
75
- rb_str_new((const char *)(str), (long)(len))
76
- #endif
77
-
78
61
  #define RBSTR_OR_QNIL(_str) \
79
62
  (_str ? NOKOGIRI_STR_NEW2(_str) : Qnil)
80
63
 
@@ -135,22 +118,6 @@ void nokogiri_root_nsdef(xmlNsPtr, xmlDocPtr);
135
118
 
136
119
  #endif
137
120
 
138
- #ifndef RSTRING_PTR
139
- #define RSTRING_PTR(s) (RSTRING(s)->ptr)
140
- #endif
141
-
142
- #ifndef RSTRING_LEN
143
- #define RSTRING_LEN(s) (RSTRING(s)->len)
144
- #endif
145
-
146
- #ifndef RARRAY_PTR
147
- #define RARRAY_PTR(a) RARRAY(a)->ptr
148
- #endif
149
-
150
- #ifndef RARRAY_LEN
151
- #define RARRAY_LEN(a) RARRAY(a)->len
152
- #endif
153
-
154
121
  #ifndef __builtin_expect
155
122
  # if defined(__GNUC__)
156
123
  # define __builtin_expect(expr, c) __builtin_expect((long)(expr), (long)(c))
@@ -20,7 +20,7 @@ static VALUE set_value(VALUE self, VALUE content)
20
20
  xmlNode *tmp;
21
21
 
22
22
  /* Encode our content */
23
- buffer = xmlEncodeEntitiesReentrant(attr->doc, (unsigned char *)StringValuePtr(content));
23
+ buffer = xmlEncodeEntitiesReentrant(attr->doc, (unsigned char *)StringValueCStr(content));
24
24
 
25
25
  attr->children = xmlStringGetNodeList(attr->doc, buffer);
26
26
  attr->last = NULL;
@@ -61,7 +61,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
61
61
 
62
62
  node = xmlNewDocProp(
63
63
  xml_doc,
64
- (const xmlChar *)StringValuePtr(name),
64
+ (const xmlChar *)StringValueCStr(name),
65
65
  NULL
66
66
  );
67
67
 
@@ -34,7 +34,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
34
34
 
35
35
  node = xmlNewDocComment(
36
36
  xml_doc,
37
- (const xmlChar *)StringValuePtr(content)
37
+ (const xmlChar *)StringValueCStr(content)
38
38
  );
39
39
 
40
40
  rb_node = Nokogiri_wrap_xml_node(klass, node);
@@ -181,7 +181,7 @@ static VALUE set_encoding(VALUE self, VALUE encoding)
181
181
  if (doc->encoding)
182
182
  free((char *) doc->encoding); /* this may produce a gcc cast warning */
183
183
 
184
- doc->encoding = xmlStrdup((xmlChar *)StringValuePtr(encoding));
184
+ doc->encoding = xmlStrdup((xmlChar *)StringValueCStr(encoding));
185
185
 
186
186
  return encoding;
187
187
  }
@@ -228,8 +228,8 @@ static VALUE read_io( VALUE klass,
228
228
  VALUE encoding,
229
229
  VALUE options )
230
230
  {
231
- const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url);
232
- const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding);
231
+ const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
232
+ const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
233
233
  VALUE error_list = rb_ary_new();
234
234
  VALUE document;
235
235
  xmlDocPtr doc;
@@ -279,8 +279,8 @@ static VALUE read_memory( VALUE klass,
279
279
  VALUE options )
280
280
  {
281
281
  const char * c_buffer = StringValuePtr(string);
282
- const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url);
283
- const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding);
282
+ const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
283
+ const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
284
284
  int len = (int)RSTRING_LEN(string);
285
285
  VALUE error_list = rb_ary_new();
286
286
  VALUE document;
@@ -322,22 +322,20 @@ static VALUE duplicate_document(int argc, VALUE *argv, VALUE self)
322
322
  xmlDocPtr doc, dup;
323
323
  VALUE copy;
324
324
  VALUE level;
325
- VALUE error_list = rb_ary_new();
325
+ VALUE error_list;
326
326
 
327
327
  if(rb_scan_args(argc, argv, "01", &level) == 0)
328
328
  level = INT2NUM((long)1);
329
329
 
330
330
  Data_Get_Struct(self, xmlDoc, doc);
331
331
 
332
- xmlResetLastError();
333
- xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
334
332
  dup = xmlCopyDoc(doc, (int)NUM2INT(level));
335
- xmlSetStructuredErrorFunc(NULL, NULL);
336
333
 
337
334
  if(dup == NULL) return Qnil;
338
335
 
339
336
  dup->type = doc->type;
340
337
  copy = Nokogiri_wrap_xml_document(rb_obj_class(self), dup);
338
+ error_list = rb_iv_get(self, "@errors");
341
339
  rb_iv_set(copy, "@errors", error_list);
342
340
  return copy ;
343
341
  }
@@ -357,7 +355,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
357
355
  version = rb_ary_entry(rest, (long)0);
358
356
  if (NIL_P(version)) version = rb_str_new2("1.0");
359
357
 
360
- doc = xmlNewDoc((xmlChar *)StringValuePtr(version));
358
+ doc = xmlNewDoc((xmlChar *)StringValueCStr(version));
361
359
  rb_doc = Nokogiri_wrap_xml_document(klass, doc);
362
360
  rb_obj_call_init(rb_doc, argc, argv);
363
361
  return rb_doc ;
@@ -385,13 +383,13 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
385
383
  * </bicycle>
386
384
  * </root>
387
385
  * EOXML
388
- *
386
+ *
389
387
  * doc.xpath("//tire").to_s # => ""
390
388
  * doc.xpath("//part:tire", "part" => "http://general-motors.com/").to_s # => "<part:tire>Michelin Model XGV</part:tire>"
391
389
  * doc.xpath("//part:tire", "part" => "http://schwinn.com/").to_s # => "<part:tire>I'm a bicycle tire!</part:tire>"
392
- *
390
+ *
393
391
  * doc.remove_namespaces!
394
- *
392
+ *
395
393
  * doc.xpath("//tire").to_s # => "<tire>Michelin Model XGV</tire><tire>I'm a bicycle tire!</tire>"
396
394
  * doc.xpath("//part:tire", "part" => "http://general-motors.com/").to_s # => ""
397
395
  * doc.xpath("//part:tire", "part" => "http://schwinn.com/").to_s # => ""
@@ -438,11 +436,11 @@ static VALUE create_entity(int argc, VALUE *argv, VALUE self)
438
436
  xmlResetLastError();
439
437
  ptr = xmlAddDocEntity(
440
438
  doc,
441
- (xmlChar *)(NIL_P(name) ? NULL : StringValuePtr(name)),
439
+ (xmlChar *)(NIL_P(name) ? NULL : StringValueCStr(name)),
442
440
  (int) (NIL_P(type) ? XML_INTERNAL_GENERAL_ENTITY : NUM2INT(type)),
443
- (xmlChar *)(NIL_P(external_id) ? NULL : StringValuePtr(external_id)),
444
- (xmlChar *)(NIL_P(system_id) ? NULL : StringValuePtr(system_id)),
445
- (xmlChar *)(NIL_P(content) ? NULL : StringValuePtr(content))
441
+ (xmlChar *)(NIL_P(external_id) ? NULL : StringValueCStr(external_id)),
442
+ (xmlChar *)(NIL_P(system_id) ? NULL : StringValueCStr(system_id)),
443
+ (xmlChar *)(NIL_P(content) ? NULL : StringValueCStr(content))
446
444
  );
447
445
 
448
446
  if(NULL == ptr) {
@@ -486,9 +484,9 @@ static int block_caller(void * ctx, xmlNodePtr _node, xmlNodePtr _parent)
486
484
  * doc.canonicalize { |obj, parent| ... }
487
485
  *
488
486
  * Canonicalize a document and return the results. Takes an optional block
489
- * that takes two parameters: the +obj+ and that node's +parent+.
487
+ * that takes two parameters: the +obj+ and that node's +parent+.
490
488
  * The +obj+ will be either a Nokogiri::XML::Node, or a Nokogiri::XML::Namespace
491
- * The block must return a non-nil, non-false value if the +obj+ passed in
489
+ * The block must return a non-nil, non-false value if the +obj+ passed in
492
490
  * should be included in the canonicalized document.
493
491
  */
494
492
  static VALUE canonicalize(int argc, VALUE* argv, VALUE self)
@@ -533,14 +531,14 @@ static VALUE canonicalize(int argc, VALUE* argv, VALUE self)
533
531
  ns = calloc((size_t)ns_len+1, sizeof(xmlChar *));
534
532
  for (i = 0 ; i < ns_len ; i++) {
535
533
  VALUE entry = rb_ary_entry(incl_ns, i);
536
- const char * ptr = StringValuePtr(entry);
534
+ const char * ptr = StringValueCStr(entry);
537
535
  ns[i] = (xmlChar*) ptr;
538
536
  }
539
537
  }
540
538
 
541
539
 
542
- xmlC14NExecute(doc, cb, ctx,
543
- (int) (NIL_P(mode) ? 0 : NUM2INT(mode)),
540
+ xmlC14NExecute(doc, cb, ctx,
541
+ (int) (NIL_P(mode) ? 0 : NUM2INT(mode)),
544
542
  ns,
545
543
  (int) RTEST(with_comments),
546
544
  buf);
@@ -9,7 +9,7 @@ static VALUE get(VALUE klass, VALUE key)
9
9
  {
10
10
  xmlCharEncodingHandlerPtr handler;
11
11
 
12
- handler = xmlFindCharEncodingHandler(StringValuePtr(key));
12
+ handler = xmlFindCharEncodingHandler(StringValueCStr(key));
13
13
  if(handler)
14
14
  return Data_Wrap_Struct(klass, NULL, NULL, handler);
15
15
 
@@ -23,7 +23,7 @@ static VALUE get(VALUE klass, VALUE key)
23
23
  */
24
24
  static VALUE delete(VALUE klass, VALUE name)
25
25
  {
26
- if(xmlDelEncodingAlias(StringValuePtr(name))) return Qnil;
26
+ if(xmlDelEncodingAlias(StringValueCStr(name))) return Qnil;
27
27
 
28
28
  return Qtrue;
29
29
  }
@@ -35,7 +35,7 @@ static VALUE delete(VALUE klass, VALUE name)
35
35
  */
36
36
  static VALUE alias(VALUE klass, VALUE from, VALUE to)
37
37
  {
38
- xmlAddEncodingAlias(StringValuePtr(from), StringValuePtr(to));
38
+ xmlAddEncodingAlias(StringValueCStr(from), StringValueCStr(to));
39
39
 
40
40
  return to;
41
41
  }
@@ -21,7 +21,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
21
21
 
22
22
  node = xmlNewReference(
23
23
  xml_doc,
24
- (const xmlChar *)StringValuePtr(name)
24
+ (const xmlChar *)StringValueCStr(name)
25
25
  );
26
26
 
27
27
  nokogiri_root_node(node);
@@ -2,6 +2,34 @@
2
2
 
3
3
  VALUE cNokogiriXmlNamespace ;
4
4
 
5
+ static void dealloc_namespace(xmlNsPtr ns)
6
+ {
7
+ /*
8
+ *
9
+ * this deallocator is only used for namespace nodes that are part of an xpath
10
+ * node set.
11
+ *
12
+ * see Nokogiri_wrap_xml_namespace() for more details.
13
+ *
14
+ */
15
+ NOKOGIRI_DEBUG_START(ns) ;
16
+ if (ns->href) {
17
+ xmlFree((xmlChar *)ns->href);
18
+ }
19
+ if (ns->prefix) {
20
+ xmlFree((xmlChar *)ns->prefix);
21
+ }
22
+ xmlFree(ns);
23
+ NOKOGIRI_DEBUG_END(ns) ;
24
+ }
25
+
26
+
27
+ int Nokogiri_namespace_eh(xmlNodePtr node)
28
+ {
29
+ return (node->type == XML_NAMESPACE_DECL);
30
+ }
31
+
32
+
5
33
  /*
6
34
  * call-seq:
7
35
  * prefix
@@ -34,37 +62,48 @@ static VALUE href(VALUE self)
34
62
  return NOKOGIRI_STR_NEW2(ns->href);
35
63
  }
36
64
 
65
+ static int part_of_an_xpath_node_set_eh(xmlNsPtr node)
66
+ {
67
+ return (node->next && ! Nokogiri_namespace_eh(node->next));
68
+ }
69
+
37
70
  VALUE Nokogiri_wrap_xml_namespace(xmlDocPtr doc, xmlNsPtr node)
38
71
  {
39
72
  VALUE ns, document, node_cache;
40
73
 
41
- assert(doc->_private);
74
+ assert(doc->type == XML_DOCUMENT_NODE || doc->type == XML_HTML_DOCUMENT_NODE);
42
75
 
43
- if(node->_private)
44
- return (VALUE)node->_private;
76
+ if (node->_private) return (VALUE)node->_private;
45
77
 
46
- ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, node);
78
+ if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
47
79
 
48
- document = DOC_RUBY_OBJECT(doc);
49
-
50
- node_cache = rb_iv_get(document, "@node_cache");
51
- rb_ary_push(node_cache, ns);
80
+ ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, node);
52
81
 
53
- rb_iv_set(ns, "@document", DOC_RUBY_OBJECT(doc));
82
+ if (DOC_RUBY_OBJECT_TEST(doc)) {
83
+ document = DOC_RUBY_OBJECT(doc);
84
+
85
+ if (part_of_an_xpath_node_set_eh(node)) {
86
+ /*
87
+ * this is a duplicate returned as part of an xpath query node set, and so
88
+ * we need to make sure we manage this memory.
89
+ *
90
+ * see comments in xml_node_set.c for more details.
91
+ */
92
+ ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, dealloc_namespace, node);
93
+ } else {
94
+ ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, node);
95
+ node_cache = rb_iv_get(document, "@node_cache");
96
+ rb_ary_push(node_cache, ns);
97
+ }
98
+
99
+ rb_iv_set(ns, "@document", document);
100
+ }
54
101
 
55
102
  node->_private = (void *)ns;
56
103
 
57
104
  return ns;
58
105
  }
59
106
 
60
- VALUE Nokogiri_wrap_xml_namespace2(VALUE document, xmlNsPtr node)
61
- {
62
- xmlDocPtr doc;
63
- Data_Get_Struct(document, xmlDoc, doc) ;
64
- return Nokogiri_wrap_xml_namespace(doc, node);
65
- }
66
-
67
-
68
107
  void init_xml_namespace()
69
108
  {
70
109
  VALUE nokogiri = rb_define_module("Nokogiri");