nokogiri 1.1.0-x86-mswin32-60 → 1.1.1-x86-mswin32-60

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.

data/History.ja.txt CHANGED
@@ -1,4 +1,20 @@
1
- === HEAD
1
+ === 1.1.1
2
+
3
+ * 新しい機能
4
+ * XML::Node#elem? を追加
5
+ * XML::Node#attribute_nodes を追加
6
+ * XML::Attr を追加
7
+ * XML::Node#delete を追加
8
+ * XML::NodeSet#inner_html を追加
9
+
10
+ * バグの修正
11
+
12
+ * HTML のノードを \r のエンティティを含まない
13
+ * CSS::SelectorHandler と XML::XPathHandler を除去
14
+ * XML::Node#attributes が Attr node を value値に返す
15
+ * XML::NodeSet が to_xml へ実行
16
+
17
+ === 1.1.0
2
18
 
3
19
  * 新しい機能
4
20
 
data/History.txt CHANGED
@@ -1,3 +1,20 @@
1
+ === 1.1.1
2
+
3
+ * New features
4
+
5
+ * Added XML::Node#elem?
6
+ * Added XML::Node#attribute_nodes
7
+ * Added XML::Attr
8
+ * XML::Node#delete added.
9
+ * XML::NodeSet#inner_html added.
10
+
11
+ * Bugfixes
12
+
13
+ * Not including an HTML entity for \r for HTML nodes.
14
+ * Removed CSS::SelectorHandler and XML::XPathHandler
15
+ * XML::Node#attributes returns an Attr node for the value.
16
+ * XML::NodeSet implements to_xml
17
+
1
18
  === 1.1.0
2
19
 
3
20
  * New Features
data/Manifest.txt CHANGED
@@ -47,7 +47,6 @@ lib/nokogiri/css/generated_tokenizer.rb
47
47
  lib/nokogiri/css/node.rb
48
48
  lib/nokogiri/css/parser.rb
49
49
  lib/nokogiri/css/parser.y
50
- lib/nokogiri/css/selector_handler.rb
51
50
  lib/nokogiri/css/syntax_error.rb
52
51
  lib/nokogiri/css/tokenizer.rb
53
52
  lib/nokogiri/css/tokenizer.rex
@@ -66,6 +65,7 @@ lib/nokogiri/html/sax/parser.rb
66
65
  lib/nokogiri/version.rb
67
66
  lib/nokogiri/xml.rb
68
67
  lib/nokogiri/xml/after_handler.rb
68
+ lib/nokogiri/xml/attr.rb
69
69
  lib/nokogiri/xml/before_handler.rb
70
70
  lib/nokogiri/xml/builder.rb
71
71
  lib/nokogiri/xml/cdata.rb
@@ -86,7 +86,6 @@ lib/nokogiri/xml/text.rb
86
86
  lib/nokogiri/xml/xpath.rb
87
87
  lib/nokogiri/xml/xpath/syntax_error.rb
88
88
  lib/nokogiri/xml/xpath_context.rb
89
- lib/nokogiri/xml/xpath_handler.rb
90
89
  lib/nokogiri/xslt.rb
91
90
  lib/nokogiri/xslt/stylesheet.rb
92
91
  test/css/test_nthiness.rb
@@ -120,6 +119,7 @@ test/hpricot/test_xml.rb
120
119
  test/html/sax/test_parser.rb
121
120
  test/html/test_builder.rb
122
121
  test/html/test_document.rb
122
+ test/html/test_node.rb
123
123
  test/test_convert_xpath.rb
124
124
  test/test_css_cache.rb
125
125
  test/test_gc.rb
@@ -128,6 +128,7 @@ test/test_nokogiri.rb
128
128
  test/test_reader.rb
129
129
  test/test_xslt_transforms.rb
130
130
  test/xml/sax/test_parser.rb
131
+ test/xml/test_attr.rb
131
132
  test/xml/test_builder.rb
132
133
  test/xml/test_cdata.rb
133
134
  test/xml/test_comment.rb
data/Rakefile CHANGED
@@ -62,6 +62,8 @@ namespace :gem do
62
62
  task :spec => ['build'] do
63
63
  File.open("#{HOE.name}.gemspec", 'w') do |f|
64
64
  HOE.spec.platform = 'jruby'
65
+ HOE.spec.files << GENERATED_PARSER
66
+ HOE.spec.files << GENERATED_TOKENIZER
65
67
  HOE.spec.extensions = []
66
68
  f.write(HOE.spec.to_ruby)
67
69
  end
@@ -91,7 +93,7 @@ file GENERATED_PARSER => "lib/nokogiri/css/parser.y" do |t|
91
93
  racc = "#{::Config::CONFIG['bindir']}/racc" if racc.empty?
92
94
  sh "#{racc} -o #{t.name} #{t.prerequisites.first}"
93
95
  rescue
94
- abort "need racc, get the tarball from http://i.loveruby.net/archive/racc/racc-1.4.5-all.tar.gz"
96
+ abort "need racc, sudo gem install racc"
95
97
  end
96
98
  end
97
99
 
@@ -242,18 +244,35 @@ def test_suite_cmdline
242
244
  cmdline = "ruby -w -I.:lib:ext:test -rtest/unit -e '%w[#{files.join(' ')}].each {|f| require f}'"
243
245
  end
244
246
 
247
+ class ValgrindTestTask < Rake::TestTask
248
+ def initialize *args
249
+ super
250
+ %w[ ext lib bin test ].each do |dir|
251
+ self.libs << dir
252
+ end
253
+ self.test_files = FileList['test/**/test_*.rb'] +
254
+ FileList['test/**/*_test.rb']
255
+ self.verbose = true
256
+ self.warning = true
257
+ end
258
+ end
259
+
260
+ VALGRIND_BASIC_OPTS = "--num-callers=50 --error-limit=no --partial-loads-ok=yes --undef-value-errors=no"
261
+
262
+ desc "run test suite under valgrind with basic ruby options"
263
+ ValgrindTestTask.new('test:valgrind').extend(Module.new {
264
+ def ruby *args
265
+ cmd = "valgrind #{VALGRIND_BASIC_OPTS} #{RUBY} #{args.join(' ')}"
266
+ puts cmd
267
+ system cmd
268
+ end
269
+ })
270
+ Rake::Task['test:valgrind'].prerequisites << :build
271
+
245
272
  namespace :test do
246
273
  # partial-loads-ok and undef-value-errors necessary to ignore
247
274
  # spurious (and eminently ignorable) warnings from the ruby
248
275
  # interpreter
249
- VALGRIND_BASIC_OPTS = "--num-callers=50 --error-limit=no --partial-loads-ok=yes --undef-value-errors=no"
250
-
251
- desc "run test suite under valgrind with basic ruby options"
252
- task :valgrind => :build do
253
- cmdline = "valgrind #{VALGRIND_BASIC_OPTS} #{test_suite_cmdline}"
254
- puts cmdline
255
- system cmdline
256
- end
257
276
 
258
277
  desc "run test suite under valgrind with memory-fill ruby options"
259
278
  task :valgrind_mem => :build do
@@ -19,35 +19,6 @@ $LIBPATH << "/opt/local/lib" if use_macports
19
19
 
20
20
  $CFLAGS << " -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
21
21
 
22
- if Config::CONFIG['target_os'] == 'mingw32'
23
- find_library('xml2', 'xmlParseDoc',
24
- File.join(ROOT, 'cross', 'libxml2-2.7.2.win32', 'bin'))
25
- find_library('xslt', 'xsltParseStylesheetDoc',
26
- File.join(ROOT, 'cross', 'libxslt-1.1.24.win32', 'bin'))
27
- find_library('exslt', 'exsltFuncRegister',
28
- File.join(ROOT, 'cross', 'libxslt-1.1.24.win32', 'bin'))
29
- else
30
- find_library('xml2', 'xmlParseDoc',
31
- LIBDIR,
32
- '/opt/local/lib',
33
- '/usr/local/lib',
34
- '/usr/lib'
35
- )
36
- find_library('xslt', 'xsltParseStylesheetDoc',
37
- LIBDIR,
38
- '/opt/local/lib',
39
- '/usr/local/lib',
40
- '/usr/lib'
41
- )
42
- find_library('exslt', 'exsltFuncRegister',
43
- LIBDIR,
44
- '/opt/local/lib',
45
- '/usr/local/lib',
46
- '/usr/lib'
47
- )
48
- end
49
-
50
-
51
22
  if Config::CONFIG['target_os'] == 'mingw32'
52
23
  header = File.join(ROOT, 'cross', 'libxml2-2.7.2.win32', 'include')
53
24
  unless find_header('libxml/xmlversion.h', header)
@@ -89,8 +60,34 @@ else
89
60
  unless find_header('libexslt/exslt.h', *HEADER_DIRS)
90
61
  abort "need libxslt"
91
62
  end
63
+ end
92
64
 
93
- version = try_constant('LIBXML_VERSION', 'libxml/xmlversion.h')
65
+ if Config::CONFIG['target_os'] == 'mingw32'
66
+ find_library('xml2', 'xmlParseDoc',
67
+ File.join(ROOT, 'cross', 'libxml2-2.7.2.win32', 'bin'))
68
+ find_library('xslt', 'xsltParseStylesheetDoc',
69
+ File.join(ROOT, 'cross', 'libxslt-1.1.24.win32', 'bin'))
70
+ find_library('exslt', 'exsltFuncRegister',
71
+ File.join(ROOT, 'cross', 'libxslt-1.1.24.win32', 'bin'))
72
+ else
73
+ find_library('xml2', 'xmlParseDoc',
74
+ LIBDIR,
75
+ '/opt/local/lib',
76
+ '/usr/local/lib',
77
+ '/usr/lib'
78
+ )
79
+ find_library('xslt', 'xsltParseStylesheetDoc',
80
+ LIBDIR,
81
+ '/opt/local/lib',
82
+ '/usr/local/lib',
83
+ '/usr/lib'
84
+ )
85
+ find_library('exslt', 'exsltFuncRegister',
86
+ LIBDIR,
87
+ '/opt/local/lib',
88
+ '/usr/local/lib',
89
+ '/usr/lib'
90
+ )
94
91
  end
95
92
 
96
93
  create_makefile('nokogiri/native')
Binary file
@@ -60,10 +60,11 @@ static VALUE internal_subset(VALUE self)
60
60
  if(!node->doc) return Qnil;
61
61
 
62
62
  doc = node->doc;
63
+ xmlDtdPtr dtd = xmlGetIntSubset(doc);
63
64
 
64
- if(!doc->intSubset) return Qnil;
65
+ if(!dtd) return Qnil;
65
66
 
66
- return Nokogiri_wrap_xml_node((xmlNodePtr)doc->intSubset);
67
+ return Nokogiri_wrap_xml_node((xmlNodePtr)dtd);
67
68
  }
68
69
 
69
70
  /*
@@ -216,22 +217,6 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
216
217
  return value;
217
218
  }
218
219
 
219
- /*
220
- * call-seq:
221
- * remove_attribute(property)
222
- *
223
- * remove the property +property+
224
- */
225
- static VALUE remove_prop(VALUE self, VALUE property)
226
- {
227
- xmlNodePtr node;
228
- xmlAttrPtr attr ;
229
- Data_Get_Struct(self, xmlNode, node);
230
- attr = xmlHasProp(node, (xmlChar *)StringValuePtr(property));
231
- if (attr) { xmlRemoveProp(attr); }
232
- return Qnil;
233
- }
234
-
235
220
  /*
236
221
  * call-seq:
237
222
  * get(attribute)
@@ -252,17 +237,17 @@ static VALUE get(VALUE self, VALUE attribute)
252
237
 
253
238
  /*
254
239
  * call-seq:
255
- * attributes()
240
+ * attribute_nodes()
256
241
  *
257
- * returns a hash containing the node's attributes.
242
+ * returns a list containing the Node attributes.
258
243
  */
259
- static VALUE attributes(VALUE self)
244
+ static VALUE attribute_nodes(VALUE self)
260
245
  {
261
246
  /* this code in the mode of xmlHasProp() */
262
247
  xmlNodePtr node ;
263
248
  VALUE attr ;
264
249
 
265
- attr = rb_hash_new() ;
250
+ attr = rb_ary_new() ;
266
251
  Data_Get_Struct(self, xmlNode, node);
267
252
 
268
253
  Nokogiri_xml_node_properties(node, attr);
@@ -270,6 +255,22 @@ static VALUE attributes(VALUE self)
270
255
  return attr ;
271
256
  }
272
257
 
258
+
259
+ /*
260
+ * call-seq:
261
+ * namespace()
262
+ *
263
+ * returns the namespace prefix for the node, if one exists.
264
+ */
265
+ static VALUE namespace(VALUE self)
266
+ {
267
+ xmlNodePtr node ;
268
+ Data_Get_Struct(self, xmlNode, node);
269
+ if (node->ns && node->ns->prefix)
270
+ return rb_str_new2((const char *)node->ns->prefix) ;
271
+ return Qnil ;
272
+ }
273
+
273
274
  /*
274
275
  * call-seq:
275
276
  * namespaces()
@@ -349,9 +350,16 @@ static VALUE add_child(VALUE self, VALUE child)
349
350
  Data_Get_Struct(child, xmlNode, node);
350
351
  Data_Get_Struct(self, xmlNode, parent);
351
352
 
353
+ xmlUnlinkNode(node) ;
354
+
352
355
  if(!(new_child = xmlAddChild(parent, node)))
353
356
  rb_raise(rb_eRuntimeError, "Could not add new child");
354
357
 
358
+ // the child was a text node that was coalesced. we need to have the object
359
+ // point at SOMETHING, or we'll totally bomb out.
360
+ if (new_child != node)
361
+ DATA_PTR(child) = new_child ;
362
+
355
363
  return Nokogiri_wrap_xml_node(new_child);
356
364
  }
357
365
 
@@ -427,10 +435,16 @@ static VALUE path(VALUE self)
427
435
  */
428
436
  static VALUE add_next_sibling(VALUE self, VALUE rb_node)
429
437
  {
430
- xmlNodePtr node, new_sibling;
438
+ xmlNodePtr node, _new_sibling, new_sibling;
431
439
  Data_Get_Struct(self, xmlNode, node);
432
- Data_Get_Struct(rb_node, xmlNode, new_sibling);
433
- xmlAddNextSibling(node, new_sibling);
440
+ Data_Get_Struct(rb_node, xmlNode, _new_sibling);
441
+
442
+ if(!(new_sibling = xmlAddNextSibling(node, _new_sibling)))
443
+ rb_raise(rb_eRuntimeError, "Could not add next sibling");
444
+
445
+ // the sibling was a text node that was coalesced. we need to have the object
446
+ // point at SOMETHING, or we'll totally bomb out.
447
+ if(new_sibling != _new_sibling) DATA_PTR(rb_node) = new_sibling;
434
448
 
435
449
  rb_funcall(rb_node, rb_intern("decorate!"), 0);
436
450
 
@@ -445,21 +459,46 @@ static VALUE add_next_sibling(VALUE self, VALUE rb_node)
445
459
  */
446
460
  static VALUE add_previous_sibling(VALUE self, VALUE rb_node)
447
461
  {
448
- xmlNodePtr node, new_sibling;
462
+ xmlNodePtr node, sibling, new_sibling;
449
463
  Check_Type(rb_node, T_DATA);
450
464
 
451
465
  Data_Get_Struct(self, xmlNode, node);
452
- Data_Get_Struct(rb_node, xmlNode, new_sibling);
466
+ Data_Get_Struct(rb_node, xmlNode, sibling);
453
467
 
454
- if(!(new_sibling = xmlAddPrevSibling(node, new_sibling)))
468
+ if(!(new_sibling = xmlAddPrevSibling(node, sibling)))
455
469
  rb_raise(rb_eRuntimeError, "Could not add previous sibling");
456
470
 
471
+ // the sibling was a text node that was coalesced. we need to have the object
472
+ // point at SOMETHING, or we'll totally bomb out.
473
+ if(sibling != new_sibling) DATA_PTR(rb_node) = new_sibling;
474
+
457
475
  rb_funcall(rb_node, rb_intern("decorate!"), 0);
458
476
 
459
- VALUE rb_new_sibling = Nokogiri_wrap_xml_node(new_sibling);
460
- rb_funcall(rb_new_sibling, rb_intern("decorate!"), 0);
477
+ return rb_node;
478
+ }
479
+
480
+ /*
481
+ * call-seq:
482
+ * to_html
483
+ *
484
+ * Returns this node as HTML
485
+ */
486
+ static VALUE to_html(VALUE self)
487
+ {
488
+ xmlBufferPtr buf ;
489
+ xmlNodePtr node ;
490
+ Data_Get_Struct(self, xmlNode, node);
491
+
492
+ VALUE html;
493
+
494
+ if(node->doc->type == XML_DOCUMENT_NODE)
495
+ return rb_funcall(self, rb_intern("to_xml"), 0);
461
496
 
462
- return rb_new_sibling;
497
+ buf = xmlBufferCreate() ;
498
+ htmlNodeDump(buf, node->doc, node);
499
+ html = rb_str_new2((char*)buf->content);
500
+ xmlBufferFree(buf);
501
+ return html ;
463
502
  }
464
503
 
465
504
  /*
@@ -567,6 +606,10 @@ VALUE Nokogiri_wrap_xml_node(xmlNodePtr node)
567
606
  klass = rb_const_get(mNokogiriXml, rb_intern("Element"));
568
607
  rb_node = Data_Wrap_Struct(klass, 0, debug_node_dealloc, node) ;
569
608
  break;
609
+ case XML_ATTRIBUTE_NODE:
610
+ klass = rb_const_get(mNokogiriXml, rb_intern("Attr"));
611
+ rb_node = Data_Wrap_Struct(klass, 0, debug_node_dealloc, node) ;
612
+ break;
570
613
  case XML_ENTITY_DECL:
571
614
  klass = rb_const_get(mNokogiriXml, rb_intern("EntityDeclaration"));
572
615
  rb_node = Data_Wrap_Struct(klass, 0, debug_node_dealloc, node) ;
@@ -590,16 +633,12 @@ VALUE Nokogiri_wrap_xml_node(xmlNodePtr node)
590
633
  }
591
634
 
592
635
 
593
- void Nokogiri_xml_node_properties(xmlNodePtr node, VALUE attr_hash)
636
+ void Nokogiri_xml_node_properties(xmlNodePtr node, VALUE attr_list)
594
637
  {
595
638
  xmlAttrPtr prop;
596
- xmlChar* propstr ;
597
639
  prop = node->properties ;
598
640
  while (prop != NULL) {
599
- propstr = xmlGetProp(node, prop->name) ;
600
- rb_hash_aset(attr_hash, rb_str_new2((const char*)prop->name),
601
- rb_str_new2((char*)propstr));
602
- xmlFree(propstr);
641
+ rb_ary_push(attr_list, Nokogiri_wrap_xml_node((xmlNodePtr)prop));
603
642
  prop = prop->next ;
604
643
  }
605
644
  }
@@ -645,9 +684,6 @@ void Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
645
684
  VALUE cNokogiriXmlNode ;
646
685
  void init_xml_node()
647
686
  {
648
- /*
649
- * HACK. This is so that rdoc will work with this C file.
650
- */
651
687
  /*
652
688
  VALUE nokogiri = rb_define_module("Nokogiri");
653
689
  VALUE xml = rb_define_module_under(nokogiri, "XML");
@@ -672,13 +708,14 @@ void init_xml_node()
672
708
  rb_define_method(klass, "key?", key_eh, 1);
673
709
  rb_define_method(klass, "blank?", blank_eh, 0);
674
710
  rb_define_method(klass, "[]=", set, 2);
675
- rb_define_method(klass, "remove_attribute", remove_prop, 1);
676
- rb_define_method(klass, "attributes", attributes, 0);
711
+ rb_define_method(klass, "attribute_nodes", attribute_nodes, 0);
712
+ rb_define_method(klass, "namespace", namespace, 0);
677
713
  rb_define_method(klass, "namespaces", namespaces, 0);
678
714
  rb_define_method(klass, "add_previous_sibling", add_previous_sibling, 1);
679
715
  rb_define_method(klass, "add_next_sibling", add_next_sibling, 1);
680
716
  rb_define_method(klass, "encode_special_chars", encode_special_chars, 1);
681
717
  rb_define_method(klass, "to_xml", to_xml, -1);
718
+ rb_define_method(klass, "to_html", to_html, 0);
682
719
  rb_define_method(klass, "dup", duplicate_node, -1);
683
720
  rb_define_method(klass, "unlink", unlink_node, 0);
684
721
  rb_define_method(klass, "internal_subset", internal_subset, 0);
@@ -78,11 +78,11 @@ static VALUE attributes_eh(VALUE self)
78
78
 
79
79
  /*
80
80
  * call-seq:
81
- * attributes
81
+ * namespaces
82
82
  *
83
- * Get a Hash of attributes for this node
83
+ * Get a hash of namespaces for this Node
84
84
  */
85
- static VALUE attributes(VALUE self)
85
+ static VALUE namespaces(VALUE self)
86
86
  {
87
87
  xmlTextReaderPtr reader;
88
88
  VALUE attr ;
@@ -98,6 +98,40 @@ static VALUE attributes(VALUE self)
98
98
  if(ptr == NULL) return Qnil;
99
99
 
100
100
  Nokogiri_xml_node_namespaces(ptr, attr);
101
+
102
+ return attr ;
103
+ }
104
+
105
+ /*
106
+ * call-seq:
107
+ * attribute_nodes
108
+ *
109
+ * Get a list of attributes for this Node
110
+ */
111
+ static VALUE attribute_nodes(VALUE self)
112
+ {
113
+ xmlTextReaderPtr reader;
114
+ VALUE attr ;
115
+
116
+ Data_Get_Struct(self, xmlTextReader, reader);
117
+
118
+ attr = rb_ary_new() ;
119
+
120
+ if (! has_attributes(reader))
121
+ return attr ;
122
+
123
+ xmlNodePtr ptr = xmlTextReaderExpand(reader);
124
+ if(ptr == NULL) return Qnil;
125
+
126
+ // FIXME I'm not sure if this is correct..... I don't really like pointing
127
+ // at this document, but I have to because of the assertions in
128
+ // the node wrapping code.
129
+ if(!ptr->doc->_private) {
130
+ VALUE rb_doc = Data_Wrap_Struct(cNokogiriXmlDocument, 0, 0, ptr->doc);
131
+ rb_iv_set(rb_doc, "@decorators", Qnil);
132
+ ptr->doc->_private = (void *)rb_doc;
133
+ }
134
+
101
135
  Nokogiri_xml_node_properties(ptr, attr);
102
136
 
103
137
  return attr ;
@@ -422,8 +456,9 @@ void init_xml_reader()
422
456
  rb_define_method(klass, "depth", depth, 0);
423
457
  rb_define_method(klass, "attribute_count", attribute_count, 0);
424
458
  rb_define_method(klass, "attribute", reader_attribute, 1);
459
+ rb_define_method(klass, "namespaces", namespaces, 0);
425
460
  rb_define_method(klass, "attribute_at", attribute_at, 1);
426
- rb_define_method(klass, "attributes", attributes, 0);
461
+ rb_define_method(klass, "attribute_nodes", attribute_nodes, 0);
427
462
  rb_define_method(klass, "attributes?", attributes_eh, 0);
428
463
  rb_define_method(klass, "value?", value_eh, 0);
429
464
  rb_define_method(klass, "default?", default_eh, 0);