nokogiri 1.6.7.2 → 1.6.8.rc1

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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -9
  3. data/CHANGELOG.ja.rdoc +18 -0
  4. data/CHANGELOG.rdoc +12 -7
  5. data/CONTRIBUTING.md +42 -0
  6. data/Gemfile +1 -1
  7. data/Manifest.txt +6 -0
  8. data/README.md +1 -1
  9. data/Rakefile +1 -1
  10. data/bin/nokogiri +2 -2
  11. data/dependencies.yml +1 -1
  12. data/ext/nokogiri/extconf.rb +3 -3
  13. data/ext/nokogiri/nokogiri.c +0 -7
  14. data/ext/nokogiri/nokogiri.h +1 -34
  15. data/ext/nokogiri/xml_document.c +2 -4
  16. data/ext/nokogiri/xml_namespace.c +56 -17
  17. data/ext/nokogiri/xml_node.c +12 -36
  18. data/ext/nokogiri/xml_node_set.c +169 -143
  19. data/ext/nokogiri/xml_node_set.h +3 -4
  20. data/ext/nokogiri/xml_sax_parser.c +2 -5
  21. data/ext/nokogiri/xml_syntax_error.c +0 -4
  22. data/ext/nokogiri/xml_syntax_error.h +0 -1
  23. data/ext/nokogiri/xml_xpath_context.c +9 -18
  24. data/lib/nokogiri.rb +3 -0
  25. data/lib/nokogiri/css/parser.rb +8 -2
  26. data/lib/nokogiri/css/parser.y +7 -2
  27. data/lib/nokogiri/version.rb +1 -1
  28. data/lib/nokogiri/xml/document.rb +7 -1
  29. data/lib/nokogiri/xml/dtd.rb +4 -4
  30. data/lib/nokogiri/xml/node.rb +2 -2
  31. data/ports/archives/libxml2-2.9.3.tar.gz +0 -0
  32. data/test/css/test_parser.rb +7 -1
  33. data/test/files/GH_1042.html +18 -0
  34. data/test/files/namespace_pressure_test.xml +1684 -0
  35. data/test/files/tlm.html +2 -1
  36. data/test/html/sax/test_parser.rb +2 -2
  37. data/test/html/test_document.rb +18 -8
  38. data/test/html/test_document_encoding.rb +46 -54
  39. data/test/html/test_document_fragment.rb +21 -22
  40. data/test/html/test_node.rb +16 -0
  41. data/test/html/test_node_encoding.rb +12 -14
  42. data/test/namespaces/test_namespaces_in_parsed_doc.rb +14 -0
  43. data/test/test_reader.rb +19 -0
  44. data/test/test_xslt_transforms.rb +5 -3
  45. data/test/xml/sax/test_parser.rb +36 -39
  46. data/test/xml/test_document.rb +7 -2
  47. data/test/xml/test_document_encoding.rb +14 -16
  48. data/test/xml/test_dtd_encoding.rb +0 -2
  49. data/test/xml/test_node_encoding.rb +78 -80
  50. data/test/xml/test_reader_encoding.rb +100 -102
  51. data/test/xslt/test_exception_handling.rb +1 -1
  52. metadata +11 -28
  53. data/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch +0 -29
  54. data/patches/libxml2/0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch +0 -31
  55. data/patches/libxml2/0003-Stop-parsing-on-entities-boundaries-errors.patch +0 -32
  56. data/patches/libxml2/0004-Cleanup-conditional-section-error-handling.patch +0 -49
  57. data/patches/libxml2/0005-CVE-2015-1819-Enforce-the-reader-to-run-in-constant-.patch +0 -177
  58. data/patches/libxml2/0006-Another-variation-of-overflow-in-Conditional-section.patch +0 -32
  59. data/patches/libxml2/0007-Fix-an-error-in-previous-Conditional-section-patch.patch +0 -28
  60. data/patches/libxml2/0008-CVE-2015-8035-Fix-XZ-compression-support-loop.patch +0 -31
  61. data/patches/libxml2/0009-Updated-config.guess.patch +0 -397
  62. data/patches/libxml2/0010-Fix-parsering-short-unclosed-comment-uninitialized-access.patch +0 -64
  63. data/patches/libxml2/0011-Avoid-extra-processing-of-MarkupDecl-when-EOF.patch +0 -35
  64. data/patches/libxml2/0012-Avoid-processing-entities-after-encoding-conversion-.patch +0 -83
  65. data/patches/libxml2/0013-CVE-2015-7497-Avoid-an-heap-buffer-overflow-in-xmlDi.patch +0 -33
  66. data/patches/libxml2/0014-CVE-2015-5312-Another-entity-expansion-issue.patch +0 -32
  67. data/patches/libxml2/0015-Add-xmlHaltParser-to-stop-the-parser.patch +0 -81
  68. data/patches/libxml2/0016-Detect-incoherency-on-GROW.patch +0 -36
  69. data/patches/libxml2/0017-CVE-2015-7500-Fix-memory-access-error-due-to-incorre.patch +0 -105
  70. data/patches/libxml2/0018-CVE-2015-8242-Buffer-overead-with-HTML-parser-in-pus.patch +0 -43
  71. data/patches/libxml2/0019-Do-not-print-error-context-when-there-is-none.patch +0 -28
  72. data/patches/libxml2/0020-xmlStopParser-reset-errNo.patch +0 -41
  73. data/patches/libxml2/0021-Reuse-xmlHaltParser-where-it-makes-sense.patch +0 -175
  74. data/ports/archives/libxml2-2.9.2.tar.gz +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44efc9ecb420ea82808bccb3a6483a4c3c495800
4
- data.tar.gz: bbe9d9ba340c51db36cd4434b111f983b80c125c
3
+ metadata.gz: bf3b512e1be5dbcd160d1fdf656009698cc5c168
4
+ data.tar.gz: 36eefac628cd098846ec6317bf4bdcc6d8fdfdc6
5
5
  SHA512:
6
- metadata.gz: ce0a7761046a3b8d4dca66efee40a71bec7014dd59f47c006592cd7d54bed65483c0a1ea914ce59796a72d4a389f9aeba24c96c96c7aabf4391ae2d52682dee7
7
- data.tar.gz: 11783290520f44642955123ae8b5ae241f6e3d4ec51ad170fb8994a6cee5f79c39de92cd4fd18bf0778f383124164a8b750e398ca6db872a070c421ae1a22132
6
+ metadata.gz: ef8390ef3ef1a8a80839213405f86e6addde5d6de4de202ed4f7432cb13c9ea368511066eb04915283294df93decec26aec6df57c2579629d13ef0afe3aed568
7
+ data.tar.gz: 74a462a70c505291c1868c99a2c1015fc1ac25a249eaac582823c9c8c4bf2d96c813eaf4cd4f561cfb40593e06cbd8f26604e4d9f46c8317e2b2138b27e3ed69
@@ -4,13 +4,13 @@ sudo: false
4
4
 
5
5
  rvm:
6
6
  - ruby-1.9.2
7
- - ruby-1.9.3
8
- - ruby-2.0.0
9
- - ruby-2.1.7
10
- - ruby-2.2.2
7
+ - 1.9.3
8
+ - 2.0
9
+ - 2.1
10
+ - 2.2.3
11
11
  - jruby-19mode
12
- - jruby-1.7.22
13
- - jruby-9.0.0.0
12
+ - jruby-1.7.23
13
+ - jruby-9.0.4.0
14
14
  - rbx-19mode
15
15
  - rbx-2
16
16
 
@@ -25,9 +25,9 @@ matrix:
25
25
  - os: osx
26
26
  rvm: jruby-19mode
27
27
  - os: osx
28
- rvm: jruby-1.7.22
28
+ rvm: jruby-1.7.23
29
29
  - os: osx
30
- rvm: jruby-9.0.0.0
30
+ rvm: jruby-9.0.4.0
31
31
  - os: osx
32
32
  rvm: rbx-19mode
33
33
  - os: osx
@@ -37,5 +37,8 @@ notifications:
37
37
  irc:
38
38
  channels:
39
39
  - "chat.freenode.net#nokogiri"
40
- use_notice: true
40
+ on_success: change
41
+ on_failure: always
42
+ template:
43
+ - "%{repository} (%{branch}:%{commit} by %{author}): %{message} (%{build_url})"
41
44
  skip_join: true
@@ -1,3 +1,21 @@
1
+ === 1.6.8 / 未リリース
2
+
3
+ ==== セキュリティ
4
+
5
+ * (MRI) Bundled Libxml2 is upgraded to 2.9.3, which fixes a series of security issues. See https://mail.gnome.org/archives/xml/2015-November/msg00012.html
6
+
7
+
8
+ ==== バグ修正
9
+
10
+ * [JRuby] fix load errors when deploying to JRuby/Torquebox (#1114) (Thanks, @atambo!)
11
+ * [JRuby] fix NPE when inspecting nodes returned by NodeSet#drop (#1042) (Thanks, @mkristian!)
12
+ * [JRuby] fix nil attriubte node's namespace in reader (#1327) (Thanks, @codekitchen!)
13
+ * [MRI] fix assertion failure while accessing attribute node's namespace in reader (#843) (Thanks, @2potatocakes!)
14
+ * [MRI] fix issue with GCing namespace nodes returned in an xpath query. (#1155)
15
+ * unescape special characters in CSS queries (#1303) (Thanks, @twalpole!)
16
+ * consistently handle empty documents (#1349)
17
+
18
+
1
19
  === 1.6.7.1 / 2015年12月16日
2
20
 
3
21
  This version pulls in several upstream patches to the vendored libxml2 and libxslt to address:
@@ -1,12 +1,19 @@
1
- === 1.6.7.2 / 2015-01-20
1
+ === 1.6.8 / unreleased
2
2
 
3
- This version pulls in several upstream patches to the vendored libxml2 and libxslt to address:
3
+ ==== Security Note
4
4
 
5
- CVE-2015-7499
5
+ * (MRI) Bundled Libxml2 is upgraded to 2.9.3, which fixes a series of security issues. See https://mail.gnome.org/archives/xml/2015-November/msg00012.html
6
6
 
7
- Ubuntu classifies this as "Priority: Low", RedHat classifies this as "Impact: Moderate", and NIST classifies this as "Severity: 5.0 (MEDIUM)".
8
7
 
9
- MITRE record is https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-7499
8
+ ==== Bug Fixes
9
+
10
+ * [JRuby] fix load errors when deploying to JRuby/Torquebox (#1114) (Thanks, @atambo!)
11
+ * [JRuby] fix NPE when inspecting nodes returned by NodeSet#drop (#1042) (Thanks, @mkristian!)
12
+ * [JRuby] fix nil attriubte node's namespace in reader (#1327) (Thanks, @codekitchen!)
13
+ * [MRI] fix assertion failure while accessing attribute node's namespace in reader (#843) (Thanks, @2potatocakes!)
14
+ * [MRI] fix issue with GCing namespace nodes returned in an xpath query. (#1155)
15
+ * unescape special characters in CSS queries (#1303) (Thanks, @twalpole!)
16
+ * consistently handle empty documents (#1349)
10
17
 
11
18
 
12
19
  === 1.6.7.1 / 2015-12-16
@@ -22,8 +29,6 @@ This version pulls in several upstream patches to the vendored libxml2 and libxs
22
29
  CVE-2015-8242
23
30
  CVE-2015-8317
24
31
 
25
- These CVEs are all low or medium priority according to Canonical, however NIST NVD gives CVE-2015-5312 a high severity score.
26
-
27
32
  See also http://www.ubuntu.com/usn/usn-2834-1/
28
33
 
29
34
 
@@ -0,0 +1,42 @@
1
+ # Issue and Pull Request Guidlines
2
+
3
+ Thank you for getting involved in making Nokogiri better!
4
+
5
+
6
+ ## Code of Conduct
7
+
8
+ For best results, be nice. Remember that Nokogiri maintainers are
9
+ volunteers, and treat them with respect.
10
+
11
+ Do not act entitled to service. Do not be rude. Do not use judgmental
12
+ or foul language.
13
+
14
+ The maintainers reserve the right to delete comments that are rude, or
15
+ that contain foul language. The maintainers reserve the right to
16
+ delete comments that they deem harassing or offensive.
17
+
18
+
19
+ ## Issues
20
+
21
+ Please read the
22
+ ["Getting Help" tutorial](http://www.nokogiri.org/tutorials/getting_help.html)
23
+ at the [nokogiri.org](http://nokogiri.org) site.
24
+
25
+ If you're reporting an issue, it must contain:
26
+
27
+ * Example code that reproduces the **observed** behavior.
28
+ * An explanation of what the **expected** behavior is.
29
+
30
+ That's it. If you don't provide that information, we'll ask you for
31
+ it, tag the story "needs more information", and then after a time will
32
+ close it if the information isn't provided.
33
+
34
+
35
+ ## Pull Requests
36
+
37
+ Pull requests must always contain a test to prevent
38
+ regressions. Preferably, the test should demonstrate the __intent__ of
39
+ the code.
40
+
41
+ We may ask you for clarification if we don't understand the intent of
42
+ the change.
data/Gemfile CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  source "https://rubygems.org/"
6
6
 
7
- gem "mini_portile2", "~>2.0.0.rc2"
7
+ gem "mini_portile2", "~>2.0.0"
8
8
 
9
9
  gem "rdoc", "~>4.0", :group => [:development, :test]
10
10
  gem "hoe-bundler", ">=1.1", :group => [:development, :test]
@@ -5,6 +5,7 @@
5
5
  .travis.yml
6
6
  CHANGELOG.ja.rdoc
7
7
  CHANGELOG.rdoc
8
+ CONTRIBUTING.md
8
9
  C_CODING_STYLE.rdoc
9
10
  Gemfile
10
11
  LICENSE.txt
@@ -241,7 +242,10 @@ lib/nokogiri/xml/xpath/syntax_error.rb
241
242
  lib/nokogiri/xml/xpath_context.rb
242
243
  lib/nokogiri/xslt.rb
243
244
  lib/nokogiri/xslt/stylesheet.rb
245
+ lib/serializer.jar
246
+ lib/xalan.jar
244
247
  lib/xercesImpl.jar
248
+ lib/xml-apis.jar
245
249
  lib/xsd/xmlparser/nokogiri.rb
246
250
  patches/sort-patches-by-date
247
251
  suppressions/README.txt
@@ -256,6 +260,7 @@ test/css/test_tokenizer.rb
256
260
  test/css/test_xpath_visitor.rb
257
261
  test/decorators/test_slop.rb
258
262
  test/files/2ch.html
263
+ test/files/GH_1042.html
259
264
  test/files/address_book.rlx
260
265
  test/files/address_book.xml
261
266
  test/files/atom.xml
@@ -268,6 +273,7 @@ test/files/exslt.xml
268
273
  test/files/exslt.xslt
269
274
  test/files/foo/foo.xsd
270
275
  test/files/metacharset.html
276
+ test/files/namespace_pressure_test.xml
271
277
  test/files/noencoding.html
272
278
  test/files/po.xml
273
279
  test/files/po.xsd
data/README.md CHANGED
@@ -121,7 +121,7 @@ Nokogiri is a large library, but here is example usage for parsing and examining
121
121
  gem, but if you want to use the system versions:
122
122
 
123
123
  * at install time, set the environment variable
124
- `USING_SYSTEM_ALLOCATOR_LIBRARY` or else use the
124
+ `NOKOGIRI_USE_SYSTEM_LIBRARIES` or else use the
125
125
  `--use-system-libraries` argument. (See
126
126
  http://nokogiri.org/tutorials/installing_nokogiri.html#using_your_system_libraries
127
127
  for specifics.)
data/Rakefile CHANGED
@@ -129,7 +129,7 @@ HOE = Hoe.spec 'nokogiri' do
129
129
  unless java?
130
130
  self.extra_deps += [
131
131
  # Keep this version in sync with the one in extconf.rb !
132
- ["mini_portile2", "~> 2.0.0.rc2"],
132
+ ["mini_portile2", "~> 2.0.0"],
133
133
  ]
134
134
  end
135
135
 
@@ -41,9 +41,9 @@ opts = OptionParser.new do |opts|
41
41
  opts.define_head "Usage: nokogiri <uri|path> [options]"
42
42
  opts.separator ""
43
43
  opts.separator "Examples:"
44
- opts.separator " nokogiri http://www.ruby-lang.org/"
44
+ opts.separator " nokogiri https://www.ruby-lang.org/"
45
45
  opts.separator " nokogiri ./public/index.html"
46
- opts.separator " curl -s http://nokogiri.org | nokogiri -e'p $_.css(\"h1\").length'"
46
+ opts.separator " curl -s http://www.nokogiri.org | nokogiri -e'p $_.css(\"h1\").length'"
47
47
  opts.separator ""
48
48
  opts.separator "Options:"
49
49
 
@@ -1,4 +1,4 @@
1
- libxml2: "2.9.2"
1
+ libxml2: "2.9.3"
2
2
  libxslt: "1.1.28"
3
3
  zlib: "1.2.8"
4
4
  libiconv: "1.14"
@@ -381,10 +381,10 @@ when using_system_libraries?
381
381
  #endif
382
382
  SRC
383
383
 
384
- try_cpp(<<-SRC) or warn "libxml2 version 2.9.2 or later is highly recommended, but proceeding anyway."
384
+ try_cpp(<<-SRC) or warn "libxml2 version 2.9.3 or later is highly recommended, but proceeding anyway."
385
385
  #include <libxml/xmlversion.h>
386
386
 
387
- #if LIBXML_VERSION < 20902
387
+ #if LIBXML_VERSION < 20903
388
388
  #error libxml2 is too old
389
389
  #endif
390
390
  SRC
@@ -393,7 +393,7 @@ else
393
393
 
394
394
  # The gem version constraint in the Rakefile is not respected at install time.
395
395
  # Keep this version in sync with the one in the Rakefile !
396
- gem "mini_portile2", "~> 2.0.0.rc2"
396
+ gem "mini_portile2", "~> 2.0.0"
397
397
  require 'mini_portile2'
398
398
  message "Using mini_portile version #{MiniPortile::VERSION}\n"
399
399
 
@@ -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))
@@ -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
  }
@@ -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");