nokogiri 1.5.3 → 1.5.4.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.

@@ -1,3 +1,17 @@
1
+ == 1.5.4 / unreleased
2
+
3
+ * Features
4
+
5
+ * The "nokogiri" script now has more verbose output when passed the `--rng` option. (Thanks, Dan Radez!)
6
+ * Build support on hardened Debian systems that use `-Werror=format-security`. #680.
7
+ * Better build support for systems with pkg-config. #584
8
+
9
+ * Bugfixes
10
+
11
+ * Segmentation fault when creating a comment node for a DocumentFragment. #677, #678.
12
+ * Treat '.' as xpath in at() and search(). #690
13
+
14
+
1
15
  == 1.5.3 / 2012-06-01
2
16
 
3
17
  * Features
@@ -1,3 +1,17 @@
1
+ == 1.5.4 / unreleased
2
+
3
+ * Features
4
+
5
+ * The "nokogiri" script now has more verbose output when passed the `--rng` option. (Thanks, Dan Radez!)
6
+ * Build support on hardened Debian systems that use `-Werror=format-security`. #680.
7
+ * Better build support for systems with pkg-config. #584
8
+
9
+ * Bugfixes
10
+
11
+ * Segmentation fault when creating a comment node for a DocumentFragment. #677, #678.
12
+ * Treat '.' as xpath in at() and search(). #690
13
+
14
+
1
15
  == 1.5.3 / 2012-06-01
2
16
 
3
17
  * Features
@@ -4,11 +4,17 @@ Please don't propose commits that only change whitespace. However, if your
4
4
  commit touches a function or section that is not using MRI Ruby conventions,
5
5
  feel free to update whitespace in the surrounding code.
6
6
 
7
+
7
8
  = WHITESPACE:
8
9
 
9
- indent level: 2
10
- indent type: Always spaces
11
- Line Breaks: LF
10
+ * indent level: 2
11
+ * indent type: Always spaces
12
+ * line Breaks: LF
13
+
14
+ This style can be automatically applied by running:
15
+
16
+ astyle --indent=spaces=2 --style=1tbs --keep-one-line-blocks $(ack -f --type=cpp --type=cc ext/nokogiri)
17
+
12
18
 
13
19
  = FUNCTION DECLARATION:
14
20
 
@@ -53,7 +53,9 @@ end
53
53
  @doc = parse_class.parse(open(uri).read, nil, encoding)
54
54
 
55
55
  if @rng
56
- puts @rng.validate(@doc)
56
+ @rng.validate(@doc).each do |error|
57
+ puts error.message
58
+ end
57
59
  else
58
60
  puts "Your document is stored in @doc..."
59
61
  IRB.start
@@ -99,7 +99,9 @@ def asplode(lib)
99
99
  abort "-----\n#{lib} is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.\n-----"
100
100
  end
101
101
 
102
- pkg_config('libxslt') if RUBY_PLATFORM =~ /mingw/
102
+ pkg_config('libxslt')
103
+ pkg_config('libxml-2.0')
104
+ pkg_config('libiconv')
103
105
 
104
106
  asplode "libxml2" unless find_header('libxml/parser.h')
105
107
  asplode "libxslt" unless find_header('libxslt/xslt.h')
@@ -43,6 +43,26 @@ void vasprintf_free (void *p)
43
43
  #endif
44
44
  #endif
45
45
 
46
+ void nokogiri_root_node(xmlNodePtr node)
47
+ {
48
+ xmlDocPtr doc;
49
+ nokogiriTuplePtr tuple;
50
+
51
+ doc = node->doc;
52
+ if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
53
+ tuple = (nokogiriTuplePtr)doc->_private;
54
+ st_insert(tuple->unlinkedNodes, (st_data_t)node, (st_data_t)node);
55
+ }
56
+
57
+ void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
58
+ {
59
+ nokogiriTuplePtr tuple;
60
+
61
+ if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
62
+ tuple = (nokogiriTuplePtr)doc->_private;
63
+ st_insert(tuple->unlinkedNodes, (st_data_t)ns, (st_data_t)ns);
64
+ }
65
+
46
66
  void Init_nokogiri()
47
67
  {
48
68
  #ifndef __MACRUBY__
@@ -120,11 +120,8 @@ extern VALUE mNokogiriHtml ;
120
120
  extern VALUE mNokogiriHtmlSax ;
121
121
  extern VALUE mNokogiriXslt ;
122
122
 
123
- #define NOKOGIRI_ROOT_NODE(_node) \
124
- st_insert(((nokogiriTuplePtr)(_node)->doc->_private)->unlinkedNodes, (st_data_t)(_node), (st_data_t)(_node))
125
-
126
- #define NOKOGIRI_ROOT_NSDEF(_nsDef, _doc) \
127
- st_insert(((nokogiriTuplePtr)(_doc)->_private)->unlinkedNodes, (st_data_t)(_nsDef), (st_data_t)(_nsDef))
123
+ void nokogiri_root_node(xmlNodePtr);
124
+ void nokogiri_root_nsdef(xmlNsPtr, xmlDocPtr);
128
125
 
129
126
  #ifdef DEBUG
130
127
 
@@ -65,7 +65,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
65
65
  NULL
66
66
  );
67
67
 
68
- NOKOGIRI_ROOT_NODE((xmlNodePtr)node);
68
+ nokogiri_root_node((xmlNodePtr)node);
69
69
 
70
70
  rb_node = Nokogiri_wrap_xml_node(klass, (xmlNodePtr)node);
71
71
  rb_obj_call_init(rb_node, argc, argv);
@@ -25,7 +25,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
25
25
  NIL_P(content) ? 0 : (int)RSTRING_LEN(content)
26
26
  );
27
27
 
28
- NOKOGIRI_ROOT_NODE(node);
28
+ nokogiri_root_node(node);
29
29
 
30
30
  rb_node = Nokogiri_wrap_xml_node(klass, node);
31
31
  rb_obj_call_init(rb_node, argc, argv);
@@ -27,7 +27,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
27
27
  rb_node = Nokogiri_wrap_xml_node(klass, node);
28
28
  rb_obj_call_init(rb_node, argc, argv);
29
29
 
30
- NOKOGIRI_ROOT_NODE(node);
30
+ nokogiri_root_node(node);
31
31
 
32
32
  if(rb_block_given_p()) rb_yield(rb_node);
33
33
 
@@ -102,7 +102,7 @@ static VALUE set_root(VALUE self, VALUE root)
102
102
 
103
103
  if(old_root) {
104
104
  xmlUnlinkNode(old_root);
105
- NOKOGIRI_ROOT_NODE(old_root);
105
+ nokogiri_root_node(old_root);
106
106
  }
107
107
 
108
108
  return root;
@@ -121,7 +121,7 @@ static VALUE set_root(VALUE self, VALUE root)
121
121
  }
122
122
 
123
123
  xmlDocSetRootElement(doc, new_root);
124
- if(old_root) NOKOGIRI_ROOT_NODE(old_root);
124
+ if(old_root) nokogiri_root_node(old_root);
125
125
  return root;
126
126
  }
127
127
 
@@ -20,7 +20,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
20
20
 
21
21
  node = xmlNewDocFragment(xml_doc->doc);
22
22
 
23
- NOKOGIRI_ROOT_NODE(node);
23
+ nokogiri_root_node(node);
24
24
 
25
25
  rb_node = Nokogiri_wrap_xml_node(klass, node);
26
26
  rb_obj_call_init(rb_node, argc, argv);
@@ -24,7 +24,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
24
24
  (const xmlChar *)StringValuePtr(name)
25
25
  );
26
26
 
27
- NOKOGIRI_ROOT_NODE(node);
27
+ nokogiri_root_node(node);
28
28
 
29
29
  rb_node = Nokogiri_wrap_xml_node(klass, node);
30
30
  rb_obj_call_init(rb_node, argc, argv);
@@ -51,7 +51,7 @@ static void relink_namespace(xmlNodePtr reparented)
51
51
  } else {
52
52
  reparented->nsDef = curr->next;
53
53
  }
54
- NOKOGIRI_ROOT_NSDEF(curr, reparented->doc);
54
+ nokogiri_root_nsdef(curr, reparented->doc);
55
55
  } else {
56
56
  prev = curr;
57
57
  }
@@ -132,7 +132,7 @@ static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_rep
132
132
  * uninteresting libxml2 implementation detail). as a result, we cannot
133
133
  * reparent the actual reparentee, so we reparent a duplicate.
134
134
  */
135
- NOKOGIRI_ROOT_NODE(reparentee);
135
+ nokogiri_root_node(reparentee);
136
136
  if (!(reparentee = xmlDocCopyNode(reparentee, pivot->doc, 1))) {
137
137
  rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
138
138
  }
@@ -162,7 +162,7 @@ static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_rep
162
162
  new_next_text = xmlDocCopyNode(next_text, pivot->doc, 1) ;
163
163
 
164
164
  xmlUnlinkNode(next_text);
165
- NOKOGIRI_ROOT_NODE(next_text);
165
+ nokogiri_root_node(next_text);
166
166
 
167
167
  xmlAddNextSibling(pivot, new_next_text);
168
168
  }
@@ -375,7 +375,7 @@ static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
375
375
  dup = xmlDocCopyNode(node, node->doc, (int)NUM2INT(level));
376
376
  if(dup == NULL) return Qnil;
377
377
 
378
- NOKOGIRI_ROOT_NODE(dup);
378
+ nokogiri_root_node(dup);
379
379
 
380
380
  return Nokogiri_wrap_xml_node(rb_obj_class(self), dup);
381
381
  }
@@ -391,7 +391,7 @@ static VALUE unlink_node(VALUE self)
391
391
  xmlNodePtr node;
392
392
  Data_Get_Struct(self, xmlNode, node);
393
393
  xmlUnlinkNode(node);
394
- NOKOGIRI_ROOT_NODE(node);
394
+ nokogiri_root_node(node);
395
395
  return self;
396
396
  }
397
397
 
@@ -489,7 +489,7 @@ static VALUE replace(VALUE self, VALUE new_node)
489
489
 
490
490
  xmlNodePtr pivot;
491
491
  Data_Get_Struct(self, xmlNode, pivot);
492
- NOKOGIRI_ROOT_NODE(pivot);
492
+ nokogiri_root_node(pivot);
493
493
 
494
494
  return reparent;
495
495
  }
@@ -681,7 +681,7 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
681
681
  if (prop && prop->children) {
682
682
  for (cur = prop->children; cur; cur = cur->next) {
683
683
  if (cur->_private) {
684
- NOKOGIRI_ROOT_NODE(cur);
684
+ nokogiri_root_node(cur);
685
685
  xmlUnlinkNode(cur);
686
686
  }
687
687
  }
@@ -901,7 +901,7 @@ static VALUE set_content(VALUE self, VALUE content)
901
901
  while (NULL != child) {
902
902
  next = child->next ;
903
903
  xmlUnlinkNode(child) ;
904
- NOKOGIRI_ROOT_NODE(child) ;
904
+ nokogiri_root_node(child);
905
905
  child = next ;
906
906
  }
907
907
 
@@ -1133,7 +1133,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
1133
1133
 
1134
1134
  node = xmlNewNode(NULL, (xmlChar *)StringValuePtr(name));
1135
1135
  node->doc = doc->doc;
1136
- NOKOGIRI_ROOT_NODE(node);
1136
+ nokogiri_root_node(node);
1137
1137
 
1138
1138
  rb_node = Nokogiri_wrap_xml_node(
1139
1139
  klass == cNokogiriXmlNode ? (VALUE)NULL : klass,
@@ -1320,6 +1320,7 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
1320
1320
  VALUE node_cache = Qnil ;
1321
1321
  VALUE rb_node = Qnil ;
1322
1322
  nokogiriTuplePtr node_has_a_document;
1323
+ xmlDocPtr doc;
1323
1324
  void (*mark_method)(xmlNodePtr) = NULL ;
1324
1325
 
1325
1326
  assert(node);
@@ -1330,7 +1331,9 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
1330
1331
  /* It's OK if the node doesn't have a fully-realized document (as in XML::Reader). */
1331
1332
  /* see https://github.com/tenderlove/nokogiri/issues/95 */
1332
1333
  /* and https://github.com/tenderlove/nokogiri/issues/439 */
1333
- node_has_a_document = DOC_RUBY_OBJECT_TEST(node->doc);
1334
+ doc = node->doc;
1335
+ if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
1336
+ node_has_a_document = DOC_RUBY_OBJECT_TEST(doc);
1334
1337
 
1335
1338
  if(node->_private && node_has_a_document)
1336
1339
  return (VALUE)node->_private;
@@ -1385,8 +1388,8 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
1385
1388
  node->_private = (void *)rb_node;
1386
1389
 
1387
1390
  if (node_has_a_document) {
1388
- document = DOC_RUBY_OBJECT(node->doc);
1389
- node_cache = DOC_NODE_CACHE(node->doc);
1391
+ document = DOC_RUBY_OBJECT(doc);
1392
+ node_cache = DOC_NODE_CACHE(doc);
1390
1393
  rb_ary_push(node_cache, rb_node);
1391
1394
  rb_funcall(document, decorate, 1, rb_node);
1392
1395
  }
@@ -27,7 +27,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
27
27
  (const xmlChar *)StringValuePtr(content)
28
28
  );
29
29
 
30
- NOKOGIRI_ROOT_NODE(node);
30
+ nokogiri_root_node(node);
31
31
 
32
32
  rb_node = Nokogiri_wrap_xml_node(klass, node);
33
33
  rb_obj_call_init(rb_node, argc, argv);
@@ -22,7 +22,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
22
22
  node = xmlNewText((xmlChar *)StringValuePtr(string));
23
23
  node->doc = doc->doc;
24
24
 
25
- NOKOGIRI_ROOT_NODE(node);
25
+ nokogiri_root_node(node);
26
26
 
27
27
  rb_node = Nokogiri_wrap_xml_node(klass, node) ;
28
28
  rb_obj_call_init(rb_node, argc, argv);
@@ -190,7 +190,7 @@ static void xpath_generic_exception_handler(void * ctx, const char *msg, ...)
190
190
  vasprintf(&message, msg, args);
191
191
  va_end(args);
192
192
 
193
- rb_raise(rb_eRuntimeError, message);
193
+ rb_raise(rb_eRuntimeError, "%s", message);
194
194
  }
195
195
 
196
196
  /*
@@ -1,6 +1,6 @@
1
1
  module Nokogiri
2
2
  # The version of Nokogiri you are using
3
- VERSION = '1.5.3'
3
+ VERSION = '1.5.4.rc1'
4
4
 
5
5
  class VersionInfo # :nodoc:
6
6
  def jruby?
@@ -3,10 +3,11 @@ module Nokogiri
3
3
  ##
4
4
  # Nokogiri::XML::Document is the main entry point for dealing with
5
5
  # XML documents. The Document is created by parsing an XML document.
6
- # See Nokogiri.XML()
6
+ # See Nokogiri::XML::Document.parse() for more information on parsing.
7
7
  #
8
8
  # For searching a Document, see Nokogiri::XML::Node#css and
9
9
  # Nokogiri::XML::Node#xpath
10
+ #
10
11
  class Document < Nokogiri::XML::Node
11
12
  # I'm ignoring unicode characters here.
12
13
  # See http://www.w3.org/TR/REC-xml-names/#ns-decl for more details.
@@ -15,13 +16,30 @@ module Nokogiri
15
16
  NCNAME_RE = /^xmlns(:[#{NCNAME_START_CHAR}][#{NCNAME_CHAR}]*)?$/
16
17
 
17
18
  ##
18
- # Parse an XML file. +string_or_io+ may be a String, or any object that
19
- # responds to _read_ and _close_ such as an IO, or StringIO.
20
- # +url+ is resource where this document is located. +encoding+ is the
21
- # encoding that should be used when processing the document. +options+
22
- # is a number that sets options in the parser, such as
23
- # Nokogiri::XML::ParseOptions::RECOVER. See the constants in
24
- # Nokogiri::XML::ParseOptions.
19
+ # Parse an XML file.
20
+ #
21
+ # +string_or_io+ may be a String, or any object that responds to
22
+ # _read_ and _close_ such as an IO, or StringIO.
23
+ #
24
+ # +url+ (optional) is the URI where this document is located.
25
+ #
26
+ # +encoding+ (optional) is the encoding that should be used when processing
27
+ # the document.
28
+ #
29
+ # +options+ (optional) is a configuration object that sets options during
30
+ # parsing, such as Nokogiri::XML::ParseOptions::RECOVER. See the
31
+ # Nokogiri::XML::ParseOptions for more information.
32
+ #
33
+ # +block+ (optional) is passed a configuration object on which
34
+ # parse options may be set.
35
+ #
36
+ # When parsing untrusted documents, it's recommended that the
37
+ # +nonet+ option be used, as shown in this example code:
38
+ #
39
+ # Nokogiri::XML::Document.parse(xml_string) { |config| config.nonet }
40
+ #
41
+ # Nokogiri.XML() is a convenience method which will call this method.
42
+ #
25
43
  def self.parse string_or_io, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML, &block
26
44
  options = Nokogiri::XML::ParseOptions.new(options) if Fixnum === options
27
45
  # Give the options to the user
@@ -103,7 +103,7 @@ module Nokogiri
103
103
 
104
104
  xpath(*(paths.map { |path|
105
105
  path = path.to_s
106
- path =~ /^(\.\/|\/|\.\.)/ ? path : CSS.xpath_for(
106
+ path =~ /^(\.\/|\/|\.\.|\.$)/ ? path : CSS.xpath_for(
107
107
  path,
108
108
  :prefix => prefix,
109
109
  :ns => ns
@@ -79,7 +79,7 @@ module Nokogiri
79
79
 
80
80
  paths.each do |path|
81
81
  sub_set += send(
82
- path =~ /^(\.\/|\/)/ ? :xpath : :css,
82
+ path =~ /^(\.\/|\/|\.\.|\.$)/ ? :xpath : :css,
83
83
  *(paths + [ns, handler]).compact
84
84
  )
85
85
  end
@@ -27,7 +27,7 @@ module Nokogiri
27
27
  SAX1 = 1 << 9
28
28
  # Implement XInclude substitution
29
29
  XINCLUDE = 1 << 10
30
- # Forbid network access
30
+ # Forbid network access. Recommended for dealing with untrusted documents.
31
31
  NONET = 1 << 11
32
32
  # Do not reuse the context dictionary
33
33
  NODICT = 1 << 12
@@ -176,6 +176,11 @@ module Nokogiri
176
176
  assert fragment.children.respond_to?(:awesome!), fragment.children.class
177
177
  end
178
178
 
179
+ def test_add_node_to_doc_fragment_segfault
180
+ frag = Nokogiri::XML::DocumentFragment.new(@xml, '<p>hello world</p>')
181
+ Nokogiri::XML::Comment.new(frag,'moo')
182
+ end
183
+
179
184
  if Nokogiri.uses_libxml?
180
185
  def test_for_libxml_in_context_fragment_parsing_bug_workaround
181
186
  10.times do
@@ -454,6 +454,11 @@ module Nokogiri
454
454
  assert_equal node, @xml.xpath('//address').first
455
455
  end
456
456
 
457
+ def test_at_self
458
+ node = @xml.at('address')
459
+ assert_equal node, node.at('.')
460
+ end
461
+
457
462
  def test_at_xpath
458
463
  node = @xml.at_xpath('//address')
459
464
  nodes = @xml.xpath('//address')
@@ -740,6 +745,11 @@ module Nokogiri
740
745
  assert_equal node.parent, parent_node
741
746
  end
742
747
 
748
+ def test_search_self
749
+ node = @xml.at('//employee')
750
+ assert_equal node.search('.').to_a, [node]
751
+ end
752
+
743
753
  def test_search_by_symbol
744
754
  assert set = @xml.search(:employee)
745
755
  assert 5, set.length
@@ -146,6 +146,11 @@ module Nokogiri
146
146
  assert_equal @xml.xpath('//employee'), custom_employees
147
147
  end
148
148
 
149
+ def test_search_self
150
+ set = @xml.xpath('//staff')
151
+ assert_equal set.to_a, set.search('.').to_a
152
+ end
153
+
149
154
  def test_search_with_custom_object
150
155
  set = @xml.xpath('//staff')
151
156
  custom_employees = set.search('//*[awesome(.)]', Class.new {
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
5
- prerelease:
4
+ hash: 2379852377
5
+ prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 3
10
- version: 1.5.3
9
+ - 4
10
+ - rc
11
+ - 1
12
+ version: 1.5.4.rc1
11
13
  platform: ruby
12
14
  authors:
13
15
  - Aaron Patterson
@@ -17,7 +19,7 @@ autorequire:
17
19
  bindir: bin
18
20
  cert_chain: []
19
21
 
20
- date: 2012-06-01 00:00:00 Z
22
+ date: 2012-06-07 00:00:00 Z
21
23
  dependencies:
22
24
  - !ruby/object:Gem::Dependency
23
25
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -503,12 +505,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
503
505
  required_rubygems_version: !ruby/object:Gem::Requirement
504
506
  none: false
505
507
  requirements:
506
- - - ">="
508
+ - - ">"
507
509
  - !ruby/object:Gem::Version
508
- hash: 3
510
+ hash: 25
509
511
  segments:
510
- - 0
511
- version: "0"
512
+ - 1
513
+ - 3
514
+ - 1
515
+ version: 1.3.1
512
516
  requirements: []
513
517
 
514
518
  rubyforge_project: nokogiri