nokogiri 1.0.4 → 1.0.5

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,10 +1,17 @@
1
+ === 1.0.5
2
+
3
+ * Bugfixes
4
+
5
+ * Added mailing list and ticket tracking information to the README.txt
6
+ * Sets ENV['PATH'] on windows if it doesn't exist
7
+ * Caching results of NodeSet#[] on Document
8
+
1
9
  === 1.0.4
2
10
 
3
11
  * Bugfixes
4
12
 
5
13
  * Changed memory mangement from weak refs to document refs
6
14
  * Plugged some memory leaks
7
- * extconf.rb now complains if your libxml2 is not between 2.6.13 and 2.6.99
8
15
  * Builder blocks can call methods from surrounding contexts
9
16
 
10
17
  === 1.0.3
@@ -3,6 +3,8 @@
3
3
  * http://nokogiri.rubyforge.org/
4
4
  * http://github.com/tenderlove/nokogiri/wikis
5
5
  * http://github.com/tenderlove/nokogiri/tree/master
6
+ * http://rubyforge.org/mailman/listinfo/nokogiri-talk
7
+ * http://nokogiri.lighthouseapp.com/projects/19607-nokogiri/overview
6
8
 
7
9
  == DESCRIPTION:
8
10
 
data/README.txt CHANGED
@@ -3,6 +3,8 @@
3
3
  * http://nokogiri.rubyforge.org/
4
4
  * http://github.com/tenderlove/nokogiri/wikis
5
5
  * http://github.com/tenderlove/nokogiri/tree/master
6
+ * http://rubyforge.org/mailman/listinfo/nokogiri-talk
7
+ * http://nokogiri.lighthouseapp.com/projects/19607-nokogiri/overview
6
8
 
7
9
  == DESCRIPTION:
8
10
 
@@ -25,6 +27,16 @@ Here is a speed test:
25
27
  Nokogiri also features an Hpricot compatibility layer to help ease the change
26
28
  to using correct CSS and XPath.
27
29
 
30
+ == SUPPORT:
31
+
32
+ The Nokogiri mailing list is available here:
33
+
34
+ * http://rubyforge.org/mailman/listinfo/nokogiri-talk
35
+
36
+ The bug tracker is available here:
37
+
38
+ * http://nokogiri.lighthouseapp.com/projects/19607-nokogiri/overview
39
+
28
40
  == SYNOPSIS:
29
41
 
30
42
  require 'nokogiri'
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ require 'nokogiri/version'
21
21
 
22
22
  HOE = Hoe.new('nokogiri', Nokogiri::VERSION) do |p|
23
23
  p.developer('Aaron Patterson', 'aaronp@rubyforge.org')
24
+ p.developer('Mike Dalessio', 'mike.dalessio@gmail.com')
24
25
  p.clean_globs = [
25
26
  'ext/nokogiri/Makefile',
26
27
  'ext/nokogiri/*.{o,so,bundle,a,log,dll}',
@@ -383,7 +383,8 @@ static VALUE get_name(VALUE self)
383
383
  {
384
384
  xmlNodePtr node;
385
385
  Data_Get_Struct(self, xmlNode, node);
386
- return rb_str_new2((const char *)node->name);
386
+ if(node->name) return rb_str_new2((const char *)node->name);
387
+ return Qnil;
387
388
  }
388
389
 
389
390
  /*
@@ -52,7 +52,22 @@ static VALUE index_at(VALUE self, VALUE number)
52
52
  if(i < 0)
53
53
  i = i + node_set->nodeNr;
54
54
 
55
- return Nokogiri_wrap_xml_node(node_set->nodeTab[i]);
55
+ VALUE document = rb_funcall(self, rb_intern("document"), 0);
56
+ if(Qnil == document)
57
+ rb_raise(rb_eRuntimeError, "You forgot to set a document.");
58
+
59
+ VALUE index = INT2NUM((int)node_set->nodeTab[i]);
60
+
61
+ VALUE node_cache = rb_funcall(document, rb_intern("node_cache"), 0);
62
+
63
+ VALUE node = rb_hash_aref(node_cache, index);
64
+
65
+ if(Qnil == node) {
66
+ node = Nokogiri_wrap_xml_node(node_set->nodeTab[i]);
67
+ rb_hash_aset(node_cache, index, node);
68
+ }
69
+
70
+ return node;
56
71
  }
57
72
 
58
73
  static void deallocate(xmlNodeSetPtr node_set)
@@ -101,7 +116,7 @@ static VALUE allocate(VALUE klass)
101
116
 
102
117
  VALUE Nokogiri_wrap_xml_node_set(xmlNodeSetPtr node_set)
103
118
  {
104
- return Data_Wrap_Struct(cNokogiriXmlNodeSet, 0, deallocate, node_set);
119
+ return Data_Wrap_Struct(cNokogiriXmlNodeSet, 0, deallocate, node_set);
105
120
  }
106
121
 
107
122
  VALUE cNokogiriXmlNodeSet ;
@@ -23,10 +23,17 @@ static VALUE node_set(VALUE self)
23
23
  xmlXPathObjectPtr xpath;
24
24
  Data_Get_Struct(self, xmlXPathObject, xpath);
25
25
 
26
+ VALUE node_set = Qnil;
27
+
26
28
  if (xpath->nodesetval)
27
- return Nokogiri_wrap_xml_node_set(xpath->nodesetval);
29
+ node_set = Nokogiri_wrap_xml_node_set(xpath->nodesetval);
30
+
31
+ if(Qnil == node_set)
32
+ node_set = Nokogiri_wrap_xml_node_set(xmlXPathNodeSetCreate(NULL));
33
+
34
+ rb_funcall(node_set, rb_intern("document="), 1, rb_iv_get(self, "@document"));
28
35
 
29
- return Nokogiri_wrap_xml_node_set(xmlXPathNodeSetCreate(NULL));
36
+ return node_set;
30
37
  }
31
38
 
32
39
  VALUE cNokogiriXmlXpath;
@@ -41,7 +41,19 @@ static VALUE evaluate(VALUE self, VALUE search_path)
41
41
  if(xpath == NULL) {
42
42
  rb_raise(rb_eRuntimeError, "Couldn't evaluate expression '%s'", query);
43
43
  }
44
- return Nokogiri_wrap_xml_xpath(xpath);
44
+
45
+ VALUE xpath_object = Nokogiri_wrap_xml_xpath(xpath);
46
+
47
+ assert(ctx->node);
48
+ assert(ctx->node->doc);
49
+ assert(ctx->node->doc->_private);
50
+
51
+ rb_funcall( xpath_object,
52
+ rb_intern("document="),
53
+ 1,
54
+ (VALUE)ctx->node->doc->_private
55
+ );
56
+ return xpath_object;
45
57
  }
46
58
 
47
59
  /*
@@ -8,9 +8,9 @@ require 'nokogiri/html/builder'
8
8
  require 'nokogiri/hpricot'
9
9
 
10
10
  # Modify the PATH on windows so that the external DLLs will get loaded.
11
- ENV['PATH'] += ";" + File.expand_path(
11
+ ENV['PATH'] = [ENV['PATH'], File.expand_path(
12
12
  File.join(File.dirname(__FILE__), "..", "ext", "nokogiri")
13
- ) if RUBY_PLATFORM =~ /mswin/i
13
+ )].compact.join(';') if RUBY_PLATFORM =~ /mswin/i
14
14
 
15
15
  require 'nokogiri/native' unless RUBY_PLATFORM =~ /java/
16
16
 
@@ -17,8 +17,9 @@ module Nokogiri
17
17
  end
18
18
 
19
19
  def make string
20
- ns = XML::NodeSet.new
21
- ns << XML::Text.new(string, XML::Document.new)
20
+ doc = XML::Document.new
21
+ ns = XML::NodeSet.new(doc)
22
+ ns << XML::Text.new(string, doc)
22
23
  ns
23
24
  end
24
25
 
@@ -1,3 +1,3 @@
1
1
  module Nokogiri
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  end
@@ -22,6 +22,10 @@ module Nokogiri
22
22
  end
23
23
  end
24
24
 
25
+ def node_cache
26
+ @node_cache ||= {}
27
+ end
28
+
25
29
  def to_xml
26
30
  serialize
27
31
  end
@@ -25,8 +25,7 @@ module Nokogiri
25
25
  ###
26
26
  # Get the list of children for this node as a NodeSet
27
27
  def children
28
- list = NodeSet.new
29
- list.document = document
28
+ list = NodeSet.new(document)
30
29
  document.decorate(list)
31
30
 
32
31
  first = self.child
@@ -56,7 +55,7 @@ module Nokogiri
56
55
  def xpath *paths
57
56
  ns = paths.last.is_a?(Hash) ? paths.pop : {}
58
57
 
59
- return NodeSet.new unless document.root
58
+ return NodeSet.new(document) unless document.root
60
59
 
61
60
  sets = paths.map { |path|
62
61
  ctx = XPathContext.new(self)
@@ -68,7 +67,7 @@ module Nokogiri
68
67
  }
69
68
  return sets.first if sets.length == 1
70
69
 
71
- NodeSet.new do |combined|
70
+ NodeSet.new(document) do |combined|
72
71
  document.decorate(combined)
73
72
  sets.each do |set|
74
73
  set.each do |node|
@@ -5,7 +5,8 @@ module Nokogiri
5
5
 
6
6
  attr_accessor :document
7
7
 
8
- def initialize
8
+ def initialize document
9
+ @document = document
9
10
  yield self if block_given?
10
11
  end
11
12
 
@@ -50,7 +51,6 @@ module Nokogiri
50
51
  # current context.
51
52
  def unlink
52
53
  each { |node| node.unlink }
53
- self.document = nil
54
54
  self
55
55
  end
56
56
  alias :remove :unlink
@@ -58,14 +58,13 @@ module Nokogiri
58
58
  ###
59
59
  # Search this document for +paths+
60
60
  def search *paths
61
- sub_set = NodeSet.new
61
+ sub_set = NodeSet.new(document)
62
62
  document.decorate(sub_set)
63
63
  each do |node|
64
64
  node.search(*paths).each do |sub_node|
65
65
  sub_set << sub_node
66
66
  end
67
67
  end
68
- sub_set.document = document
69
68
  sub_set
70
69
  end
71
70
  alias :/ :search
@@ -1,6 +1,8 @@
1
1
  module Nokogiri
2
2
  module XML
3
3
  class XPath
4
+ attr_accessor :document
5
+
4
6
  end
5
7
  end
6
8
  end
@@ -78,6 +78,17 @@ module Nokogiri
78
78
  assert @xml.document
79
79
  end
80
80
 
81
+ def test_singleton_methods
82
+ assert node_set = @xml.search('//name')
83
+ assert node_set.length > 0
84
+ node = node_set.first
85
+ def node.test
86
+ 'test'
87
+ end
88
+ assert node_set = @xml.search('//name')
89
+ assert_equal 'test', node_set.first.test
90
+ end
91
+
81
92
  def test_multiple_search
82
93
  assert node_set = @xml.search('//employee', '//name')
83
94
  employees = @xml.search('//employee')
@@ -54,7 +54,6 @@ module Nokogiri
54
54
  assert !node.previous_sibling
55
55
  assert !node.next_sibling
56
56
  end
57
- assert !set.document
58
57
  assert_no_match(/Hello world/, xml.to_s)
59
58
  end
60
59
 
@@ -76,7 +75,7 @@ module Nokogiri
76
75
  end
77
76
 
78
77
  def test_new_nodeset
79
- node_set = Nokogiri::XML::NodeSet.new
78
+ node_set = Nokogiri::XML::NodeSet.new(@xml)
80
79
  assert_equal(0, node_set.length)
81
80
  node = Nokogiri::XML::Node.new('form', @xml)
82
81
  node_set << node
metadata CHANGED
@@ -1,21 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
+ - Mike Dalessio
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2008-11-09 00:00:00 -08:00
13
+ date: 2008-11-11 00:00:00 -08:00
13
14
  default_executable:
14
15
  dependencies: []
15
16
 
16
17
  description: "Nokogiri (\xE9\x8B\xB8) is an HTML, XML, SAX, and Reader parser."
17
18
  email:
18
19
  - aaronp@rubyforge.org
20
+ - mike.dalessio@gmail.com
19
21
  executables: []
20
22
 
21
23
  extensions:
@@ -172,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
174
  requirements: []
173
175
 
174
176
  rubyforge_project: nokogiri
175
- rubygems_version: 1.2.0
177
+ rubygems_version: 1.3.1
176
178
  signing_key:
177
179
  specification_version: 2
178
180
  summary: "Nokogiri (\xE9\x8B\xB8) is an HTML, XML, SAX, and Reader parser."