nokogiri 1.10.8-java → 1.11.0.rc3-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/README.md +24 -22
  3. data/ext/java/nokogiri/HtmlDocument.java +34 -46
  4. data/ext/java/nokogiri/HtmlSaxParserContext.java +87 -57
  5. data/ext/java/nokogiri/NokogiriService.java +1 -1
  6. data/ext/java/nokogiri/XmlAttr.java +13 -20
  7. data/ext/java/nokogiri/XmlAttributeDecl.java +11 -12
  8. data/ext/java/nokogiri/XmlCdata.java +3 -4
  9. data/ext/java/nokogiri/XmlComment.java +1 -1
  10. data/ext/java/nokogiri/XmlDocument.java +148 -175
  11. data/ext/java/nokogiri/XmlDocumentFragment.java +13 -31
  12. data/ext/java/nokogiri/XmlDtd.java +5 -8
  13. data/ext/java/nokogiri/XmlElement.java +1 -20
  14. data/ext/java/nokogiri/XmlElementDecl.java +23 -28
  15. data/ext/java/nokogiri/XmlEntityDecl.java +23 -27
  16. data/ext/java/nokogiri/XmlEntityReference.java +2 -2
  17. data/ext/java/nokogiri/XmlNamespace.java +72 -89
  18. data/ext/java/nokogiri/XmlNode.java +300 -401
  19. data/ext/java/nokogiri/XmlNodeSet.java +72 -77
  20. data/ext/java/nokogiri/XmlReader.java +10 -11
  21. data/ext/java/nokogiri/XmlSaxParserContext.java +7 -7
  22. data/ext/java/nokogiri/XmlSchema.java +3 -3
  23. data/ext/java/nokogiri/XmlText.java +12 -9
  24. data/ext/java/nokogiri/XmlXpathContext.java +7 -7
  25. data/ext/java/nokogiri/XsltStylesheet.java +7 -15
  26. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +4 -10
  27. data/ext/java/nokogiri/internals/NokogiriHelpers.java +71 -135
  28. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +90 -58
  29. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +5 -4
  30. data/ext/java/nokogiri/internals/ParserContext.java +27 -73
  31. data/ext/java/nokogiri/internals/ReaderNode.java +2 -4
  32. data/ext/java/nokogiri/internals/XmlDomParserContext.java +17 -32
  33. data/ext/nokogiri/extconf.rb +50 -37
  34. data/ext/nokogiri/nokogiri.c +12 -6
  35. data/ext/nokogiri/nokogiri.h +13 -0
  36. data/ext/nokogiri/xml_document.c +16 -2
  37. data/ext/nokogiri/xml_io.c +8 -6
  38. data/ext/nokogiri/xml_node.c +20 -0
  39. data/ext/nokogiri/xml_reader.c +6 -17
  40. data/ext/nokogiri/xml_schema.c +29 -0
  41. data/ext/nokogiri/xslt_stylesheet.c +0 -4
  42. data/lib/nokogiri.rb +3 -20
  43. data/lib/nokogiri/css.rb +1 -0
  44. data/lib/nokogiri/css/node.rb +1 -0
  45. data/lib/nokogiri/css/parser.rb +61 -60
  46. data/lib/nokogiri/css/parser_extras.rb +39 -36
  47. data/lib/nokogiri/css/syntax_error.rb +1 -0
  48. data/lib/nokogiri/css/tokenizer.rb +1 -0
  49. data/lib/nokogiri/css/xpath_visitor.rb +3 -1
  50. data/lib/nokogiri/decorators/slop.rb +1 -0
  51. data/lib/nokogiri/html.rb +1 -0
  52. data/lib/nokogiri/html/builder.rb +1 -0
  53. data/lib/nokogiri/html/document.rb +1 -0
  54. data/lib/nokogiri/html/document_fragment.rb +1 -0
  55. data/lib/nokogiri/html/element_description.rb +1 -0
  56. data/lib/nokogiri/html/element_description_defaults.rb +1 -0
  57. data/lib/nokogiri/html/entity_lookup.rb +1 -0
  58. data/lib/nokogiri/html/sax/parser.rb +1 -0
  59. data/lib/nokogiri/html/sax/parser_context.rb +1 -0
  60. data/lib/nokogiri/html/sax/push_parser.rb +1 -0
  61. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  62. data/lib/nokogiri/nokogiri.jar +0 -0
  63. data/lib/nokogiri/syntax_error.rb +1 -0
  64. data/lib/nokogiri/version.rb +86 -45
  65. data/lib/nokogiri/xml.rb +1 -0
  66. data/lib/nokogiri/xml/attr.rb +1 -0
  67. data/lib/nokogiri/xml/attribute_decl.rb +1 -0
  68. data/lib/nokogiri/xml/builder.rb +3 -2
  69. data/lib/nokogiri/xml/cdata.rb +1 -0
  70. data/lib/nokogiri/xml/character_data.rb +1 -0
  71. data/lib/nokogiri/xml/document.rb +3 -8
  72. data/lib/nokogiri/xml/document_fragment.rb +1 -0
  73. data/lib/nokogiri/xml/dtd.rb +1 -0
  74. data/lib/nokogiri/xml/element_content.rb +1 -0
  75. data/lib/nokogiri/xml/element_decl.rb +1 -0
  76. data/lib/nokogiri/xml/entity_decl.rb +1 -0
  77. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  78. data/lib/nokogiri/xml/namespace.rb +1 -0
  79. data/lib/nokogiri/xml/node.rb +539 -224
  80. data/lib/nokogiri/xml/node/save_options.rb +1 -0
  81. data/lib/nokogiri/xml/node_set.rb +1 -0
  82. data/lib/nokogiri/xml/notation.rb +1 -0
  83. data/lib/nokogiri/xml/parse_options.rb +4 -3
  84. data/lib/nokogiri/xml/pp.rb +1 -0
  85. data/lib/nokogiri/xml/pp/character_data.rb +1 -0
  86. data/lib/nokogiri/xml/pp/node.rb +1 -0
  87. data/lib/nokogiri/xml/processing_instruction.rb +1 -0
  88. data/lib/nokogiri/xml/reader.rb +7 -3
  89. data/lib/nokogiri/xml/relax_ng.rb +1 -0
  90. data/lib/nokogiri/xml/sax.rb +1 -0
  91. data/lib/nokogiri/xml/sax/document.rb +1 -0
  92. data/lib/nokogiri/xml/sax/parser.rb +1 -0
  93. data/lib/nokogiri/xml/sax/parser_context.rb +1 -0
  94. data/lib/nokogiri/xml/sax/push_parser.rb +1 -0
  95. data/lib/nokogiri/xml/schema.rb +1 -0
  96. data/lib/nokogiri/xml/searchable.rb +22 -15
  97. data/lib/nokogiri/xml/syntax_error.rb +1 -0
  98. data/lib/nokogiri/xml/text.rb +1 -0
  99. data/lib/nokogiri/xml/xpath.rb +1 -0
  100. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -0
  101. data/lib/nokogiri/xml/xpath_context.rb +1 -0
  102. data/lib/nokogiri/xslt.rb +1 -0
  103. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  104. data/lib/xsd/xmlparser/nokogiri.rb +1 -0
  105. metadata +53 -34
  106. data/ext/java/nokogiri/internals/NokogiriEncodingReaderWrapper.java +0 -107
  107. data/ext/java/nokogiri/internals/UncloseableInputStream.java +0 -102
@@ -24,6 +24,10 @@ def openbsd?
24
24
  RbConfig::CONFIG['target_os'] =~ /openbsd/
25
25
  end
26
26
 
27
+ def aix?
28
+ RbConfig::CONFIG["target_os"] =~ /aix/
29
+ end
30
+
27
31
  def nix?
28
32
  ! (windows? || solaris? || darwin?)
29
33
  end
@@ -419,7 +423,7 @@ if windows?
419
423
  $CFLAGS << " -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF"
420
424
  end
421
425
 
422
- if solaris?
426
+ if solaris? || aix?
423
427
  $CFLAGS << " -DUSE_INCLUDED_VASPRINTF"
424
428
  end
425
429
 
@@ -466,7 +470,7 @@ else
466
470
  # The gem version constraint in the Rakefile is not respected at install time.
467
471
  # Keep this version in sync with the one in the Rakefile !
468
472
  require 'rubygems'
469
- gem 'mini_portile2', '~> 2.4.0'
473
+ gem 'mini_portile2', '~> 2.5.0'
470
474
  require 'mini_portile2'
471
475
  message "Using mini_portile version #{MiniPortile::VERSION}\n"
472
476
 
@@ -486,50 +490,60 @@ else
486
490
  url: "http://zlib.net/fossils/#{recipe.name}-#{recipe.version}.tar.gz",
487
491
  sha256: dependencies["zlib"]["sha256"]
488
492
  }]
489
- class << recipe
490
- attr_accessor :cross_build_p
491
-
492
- def configure
493
- Dir.chdir work_path do
494
- mk = File.read 'win32/Makefile.gcc'
495
- File.open 'win32/Makefile.gcc', 'wb' do |f|
496
- f.puts "BINARY_PATH = #{path}/bin"
497
- f.puts "LIBRARY_PATH = #{path}/lib"
498
- f.puts "INCLUDE_PATH = #{path}/include"
499
- mk.sub!(/^PREFIX\s*=\s*$/, "PREFIX = #{host}-") if cross_build_p
500
- f.puts mk
493
+ if windows?
494
+ class << recipe
495
+ attr_accessor :cross_build_p
496
+
497
+ def configure
498
+ Dir.chdir work_path do
499
+ mk = File.read 'win32/Makefile.gcc'
500
+ File.open 'win32/Makefile.gcc', 'wb' do |f|
501
+ f.puts "BINARY_PATH = #{path}/bin"
502
+ f.puts "LIBRARY_PATH = #{path}/lib"
503
+ f.puts "INCLUDE_PATH = #{path}/include"
504
+ mk.sub!(/^PREFIX\s*=\s*$/, "PREFIX = #{host}-") if cross_build_p
505
+ f.puts mk
506
+ end
501
507
  end
502
508
  end
503
- end
504
509
 
505
- def configured?
506
- Dir.chdir work_path do
507
- !! (File.read('win32/Makefile.gcc') =~ /^BINARY_PATH/)
510
+ def configured?
511
+ Dir.chdir work_path do
512
+ !! (File.read('win32/Makefile.gcc') =~ /^BINARY_PATH/)
513
+ end
508
514
  end
509
- end
510
515
 
511
- def compile
512
- execute "compile", "make -f win32/Makefile.gcc"
513
- end
516
+ def compile
517
+ execute "compile", "make -f win32/Makefile.gcc"
518
+ end
514
519
 
515
- def install
516
- execute "install", "make -f win32/Makefile.gcc install"
520
+ def install
521
+ execute "install", "make -f win32/Makefile.gcc install"
522
+ end
523
+ end
524
+ recipe.cross_build_p = cross_build_p
525
+ else
526
+ class << recipe
527
+ def configure
528
+ execute "configure", ["env", "CHOST=#{host}", "CFLAGS=-fPIC #{ENV['CFLAGS']}", "./configure", "--static", configure_prefix]
529
+ end
517
530
  end
518
531
  end
519
- recipe.cross_build_p = cross_build_p
520
532
  end
521
533
 
522
- libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p, cross_build_p) do |recipe|
523
- recipe.files = [{
524
- url: "http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
525
- sha256: dependencies["libiconv"]["sha256"]
526
- }]
527
- recipe.configure_options += [
528
- "CPPFLAGS=-Wall",
529
- "CFLAGS=-O2 -g",
530
- "CXXFLAGS=-O2 -g",
531
- "LDFLAGS="
532
- ]
534
+ unless nix?
535
+ libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p, cross_build_p) do |recipe|
536
+ recipe.files = [{
537
+ url: "http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
538
+ sha256: dependencies["libiconv"]["sha256"]
539
+ }]
540
+ recipe.configure_options += [
541
+ "CPPFLAGS=-Wall",
542
+ "CFLAGS=-O2 -g",
543
+ "CXXFLAGS=-O2 -g",
544
+ "LDFLAGS="
545
+ ]
546
+ end
533
547
  end
534
548
  else
535
549
  if darwin? && !have_header('iconv.h')
@@ -617,7 +631,6 @@ EOM
617
631
  end
618
632
 
619
633
  # Defining a macro that expands to a C string; double quotes are significant.
620
- $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATH=\"#{recipe.path}\"".inspect
621
634
  $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATCHES=\"#{recipe.patch_files.map { |path| File.basename(path) }.join(' ')}\"".inspect
622
635
 
623
636
  case libname
@@ -76,24 +76,30 @@ void Init_nokogiri()
76
76
  mNokogiriHtmlSax = rb_define_module_under(mNokogiriHtml, "SAX");
77
77
 
78
78
  rb_const_set( mNokogiri,
79
- rb_intern("LIBXML_VERSION"),
79
+ rb_intern("LIBXML_COMPILED_VERSION"),
80
80
  NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION)
81
81
  );
82
82
  rb_const_set( mNokogiri,
83
- rb_intern("LIBXML_PARSER_VERSION"),
83
+ rb_intern("LIBXML_LOADED_VERSION"),
84
84
  NOKOGIRI_STR_NEW2(xmlParserVersion)
85
85
  );
86
86
 
87
+
88
+ rb_const_set( mNokogiri,
89
+ rb_intern("LIBXSLT_COMPILED_VERSION"),
90
+ NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION)
91
+ );
92
+ rb_const_set( mNokogiri,
93
+ rb_intern("LIBXSLT_LOADED_VERSION"),
94
+ NOKOGIRI_STR_NEW2(xsltEngineVersion)
95
+ );
96
+
87
97
  #ifdef NOKOGIRI_USE_PACKAGED_LIBRARIES
88
98
  rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qtrue);
89
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATH"), NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATH));
90
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATH"), NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATH));
91
99
  rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
92
100
  rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
93
101
  #else
94
102
  rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qfalse);
95
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATH"), Qnil);
96
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATH"), Qnil);
97
103
  rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATCHES"), Qnil);
98
104
  rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATCHES"), Qnil);
99
105
  #endif
@@ -1,6 +1,18 @@
1
1
  #ifndef NOKOGIRI_NATIVE
2
2
  #define NOKOGIRI_NATIVE
3
3
 
4
+ #if _MSC_VER
5
+ #ifndef WIN32_LEAN_AND_MEAN
6
+ #define WIN32_LEAN_AND_MEAN
7
+ #endif /* WIN32_LEAN_AND_MEAN */
8
+ #ifndef WIN32
9
+ #define WIN32
10
+ #endif /* WIN32 */
11
+ #include <winsock2.h>
12
+ #include <ws2tcpip.h>
13
+ #include <windows.h>
14
+ #endif
15
+
4
16
  #include <stdlib.h>
5
17
  #include <string.h>
6
18
  #include <assert.h>
@@ -29,6 +41,7 @@ int vasprintf (char **strp, const char *fmt, va_list ap);
29
41
  #include <libxml/relaxng.h>
30
42
  #include <libxml/xinclude.h>
31
43
  #include <libxslt/extensions.h>
44
+ #include <libxslt/xsltconfig.h>
32
45
  #include <libxml/c14n.h>
33
46
  #include <ruby.h>
34
47
  #include <ruby/st.h>
@@ -1,6 +1,6 @@
1
1
  #include <xml_document.h>
2
2
 
3
- static int dealloc_node_i(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
3
+ static int dealloc_node_i2(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
4
4
  {
5
5
  switch(node->type) {
6
6
  case XML_ATTRIBUTE_NODE:
@@ -20,6 +20,11 @@ static int dealloc_node_i(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
20
20
  return ST_CONTINUE;
21
21
  }
22
22
 
23
+ static int dealloc_node_i(st_data_t key, st_data_t node, st_data_t doc)
24
+ {
25
+ return dealloc_node_i2((xmlNodePtr)key, (xmlNodePtr)node, (xmlDocPtr)doc);
26
+ }
27
+
23
28
  static void remove_private(xmlNodePtr node)
24
29
  {
25
30
  xmlNodePtr child;
@@ -38,6 +43,15 @@ static void remove_private(xmlNodePtr node)
38
43
  node->_private = NULL;
39
44
  }
40
45
 
46
+ static void mark(xmlDocPtr doc)
47
+ {
48
+ nokogiriTuplePtr tuple = (nokogiriTuplePtr)doc->_private;
49
+ if(tuple) {
50
+ rb_gc_mark(tuple->doc);
51
+ rb_gc_mark(tuple->node_cache);
52
+ }
53
+ }
54
+
41
55
  static void dealloc(xmlDocPtr doc)
42
56
  {
43
57
  st_table *node_hash;
@@ -588,7 +602,7 @@ VALUE Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc)
588
602
 
589
603
  VALUE rb_doc = Data_Wrap_Struct(
590
604
  klass ? klass : cNokogiriXmlDocument,
591
- 0,
605
+ mark,
592
606
  dealloc,
593
607
  doc
594
608
  );
@@ -2,12 +2,13 @@
2
2
 
3
3
  static ID id_read, id_write;
4
4
 
5
- VALUE read_check(VALUE *args) {
5
+ VALUE read_check(VALUE val) {
6
+ VALUE *args = (VALUE *)val;
6
7
  return rb_funcall(args[0], id_read, 1, args[1]);
7
8
  }
8
9
 
9
- VALUE read_failed(void) {
10
- return Qundef;
10
+ VALUE read_failed(VALUE arg, VALUE exc) {
11
+ return Qundef;
11
12
  }
12
13
 
13
14
  int io_read_callback(void * ctx, char * buffer, int len) {
@@ -30,12 +31,13 @@ int io_read_callback(void * ctx, char * buffer, int len) {
30
31
  return (int)safe_len;
31
32
  }
32
33
 
33
- VALUE write_check(VALUE *args) {
34
+ VALUE write_check(VALUE val) {
35
+ VALUE *args = (VALUE *)val;
34
36
  return rb_funcall(args[0], id_write, 1, args[1]);
35
37
  }
36
38
 
37
- VALUE write_failed(void) {
38
- return Qundef;
39
+ VALUE write_failed(VALUE arg, VALUE exc) {
40
+ return Qundef;
39
41
  }
40
42
 
41
43
  int io_write_callback(void * ctx, char * buffer, int len) {
@@ -1332,6 +1332,25 @@ static VALUE line(VALUE self)
1332
1332
  return INT2NUM(xmlGetLineNo(node));
1333
1333
  }
1334
1334
 
1335
+ /*
1336
+ * call-seq:
1337
+ * line=(num)
1338
+ *
1339
+ * Sets the line for this Node. num must be less than 65535.
1340
+ */
1341
+ static VALUE set_line(VALUE self, VALUE num)
1342
+ {
1343
+ xmlNodePtr node;
1344
+ Data_Get_Struct(self, xmlNode, node);
1345
+
1346
+ int value = NUM2INT(num);
1347
+ if (value < 65535) {
1348
+ node->line = value;
1349
+ }
1350
+
1351
+ return num;
1352
+ }
1353
+
1335
1354
  /*
1336
1355
  * call-seq:
1337
1356
  * add_namespace_definition(prefix, href)
@@ -1728,6 +1747,7 @@ void init_xml_node()
1728
1747
  rb_define_method(klass, "create_external_subset", create_external_subset, 3);
1729
1748
  rb_define_method(klass, "pointer_id", pointer_id, 0);
1730
1749
  rb_define_method(klass, "line", line, 0);
1750
+ rb_define_method(klass, "line=", set_line, 1);
1731
1751
  rb_define_method(klass, "content", get_native_content, 0);
1732
1752
  rb_define_method(klass, "native_content=", set_native_content, 1);
1733
1753
  rb_define_method(klass, "lang", get_lang, 0);
@@ -28,35 +28,24 @@ static int has_attributes(xmlTextReaderPtr reader)
28
28
  static void Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
29
29
  {
30
30
  xmlNsPtr ns;
31
- static char buffer[XMLNS_BUFFER_LEN] ;
32
- char *key ;
33
- size_t keylen ;
31
+ VALUE key;
34
32
 
35
33
  if (node->type != XML_ELEMENT_NODE) return ;
36
34
 
37
35
  ns = node->nsDef;
38
36
  while (ns != NULL) {
39
37
 
40
- keylen = XMLNS_PREFIX_LEN + (ns->prefix ? (strlen((const char*)ns->prefix) + 1) : 0) ;
41
- if (keylen > XMLNS_BUFFER_LEN) {
42
- key = (char*)malloc(keylen) ;
43
- } else {
44
- key = buffer ;
45
- }
46
-
38
+ key = rb_enc_str_new_cstr(XMLNS_PREFIX, rb_utf8_encoding());
47
39
  if (ns->prefix) {
48
- sprintf(key, "%s:%s", XMLNS_PREFIX, ns->prefix);
49
- } else {
50
- sprintf(key, "%s", XMLNS_PREFIX);
40
+ rb_str_cat_cstr(key, ":");
41
+ rb_str_cat_cstr(key, (const char*)ns->prefix);
51
42
  }
52
43
 
44
+ key = rb_str_conv_enc(key, rb_utf8_encoding(), rb_default_internal_encoding());
53
45
  rb_hash_aset(attr_hash,
54
- NOKOGIRI_STR_NEW2(key),
46
+ key,
55
47
  (ns->href ? NOKOGIRI_STR_NEW2(ns->href) : Qnil)
56
48
  );
57
- if (key != buffer) {
58
- free(key);
59
- }
60
49
  ns = ns->next ;
61
50
  }
62
51
  }
@@ -133,6 +133,31 @@ static VALUE read_memory(VALUE klass, VALUE content)
133
133
  return rb_schema;
134
134
  }
135
135
 
136
+ /* Schema creation will remove and deallocate "blank" nodes.
137
+ * If those blank nodes have been exposed to Ruby, they could get freed
138
+ * out from under the VALUE pointer. This function checks to see if any of
139
+ * those nodes have been exposed to Ruby, and if so we should raise an exception.
140
+ */
141
+ static int has_blank_nodes_p(VALUE cache)
142
+ {
143
+ long i;
144
+
145
+ if (NIL_P(cache)) {
146
+ return 0;
147
+ }
148
+
149
+ for (i = 0; i < RARRAY_LEN(cache); i++) {
150
+ xmlNodePtr node;
151
+ VALUE element = rb_ary_entry(cache, i);
152
+ Data_Get_Struct(element, xmlNode, node);
153
+ if (xmlIsBlankNode(node)) {
154
+ return 1;
155
+ }
156
+ }
157
+
158
+ return 0;
159
+ }
160
+
136
161
  /*
137
162
  * call-seq:
138
163
  * from_document(doc)
@@ -152,6 +177,10 @@ static VALUE from_document(VALUE klass, VALUE document)
152
177
  /* In case someone passes us a node. ugh. */
153
178
  doc = doc->doc;
154
179
 
180
+ if (has_blank_nodes_p(DOC_NODE_CACHE(doc))) {
181
+ rb_raise(rb_eArgError, "Creating a schema from a document that has blank nodes exposed to Ruby is dangerous");
182
+ }
183
+
155
184
  ctx = xmlSchemaNewDocParserCtxt(doc);
156
185
 
157
186
  errors = rb_ary_new();
@@ -109,10 +109,6 @@ static VALUE serialize(VALUE self, VALUE xmlobj)
109
109
  return rval ;
110
110
  }
111
111
 
112
- static void swallow_superfluous_xml_errors(void * userdata, xmlErrorPtr error, ...)
113
- {
114
- }
115
-
116
112
  /*
117
113
  * call-seq:
118
114
  * transform(document, params = [])
@@ -1,28 +1,11 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
  # Modify the PATH on windows so that the external DLLs will get loaded.
3
4
 
4
5
  require 'rbconfig'
5
6
 
6
7
  if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
7
- # The line below caused a problem on non-GAE rack environment.
8
- # unless defined?(JRuby::Rack::VERSION) || defined?(AppEngine::ApiProxy)
9
- #
10
- # However, simply cutting defined?(JRuby::Rack::VERSION) off resulted in
11
- # an unable-to-load-nokogiri problem. Thus, now, Nokogiri checks the presense
12
- # of appengine-rack.jar in $LOAD_PATH. If Nokogiri is on GAE, Nokogiri
13
- # should skip loading xml jars. This is because those are in WEB-INF/lib and
14
- # already set in the classpath.
15
- unless $LOAD_PATH.to_s.include?("appengine-rack")
16
- require 'stringio'
17
- require 'isorelax.jar'
18
- require 'jing.jar'
19
- require 'nekohtml.jar'
20
- require 'nekodtd.jar'
21
- require 'xercesImpl.jar'
22
- require 'serializer.jar'
23
- require 'xalan.jar'
24
- require 'xml-apis.jar'
25
- end
8
+ require 'nokogiri/jruby/dependencies'
26
9
  end
27
10
 
28
11
  begin
@@ -54,7 +37,7 @@ require 'nokogiri/html/builder'
54
37
  #
55
38
  # # Get a Nokogiri::HTML:Document for the page we’re interested in...
56
39
  #
57
- # doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
40
+ # doc = Nokogiri::HTML(URI.open('http://www.google.com/search?q=tenderlove'))
58
41
  #
59
42
  # # Do funky things with it using Nokogiri::XML::Node methods...
60
43
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'nokogiri/css/node'
2
3
  require 'nokogiri/css/xpath_visitor'
3
4
  x = $-w