nokogiri 1.12.4-java → 1.13.2-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 (106) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +9 -7
  4. data/bin/nokogiri +63 -50
  5. data/dependencies.yml +11 -62
  6. data/ext/java/nokogiri/Html4SaxPushParser.java +14 -19
  7. data/ext/java/nokogiri/XmlDocumentFragment.java +4 -3
  8. data/ext/java/nokogiri/XmlNamespace.java +0 -8
  9. data/ext/java/nokogiri/XmlNode.java +23 -2
  10. data/ext/java/nokogiri/XmlNodeSet.java +0 -4
  11. data/ext/java/nokogiri/XmlReader.java +12 -0
  12. data/ext/java/nokogiri/XmlSaxParserContext.java +31 -93
  13. data/ext/java/nokogiri/XmlSaxPushParser.java +17 -25
  14. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +1 -1
  15. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +29 -8
  16. data/ext/java/nokogiri/internals/NokogiriHandler.java +6 -24
  17. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +9 -8
  18. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +10 -9
  19. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +7 -6
  20. data/ext/java/nokogiri/internals/SaveContextVisitor.java +2 -0
  21. data/ext/java/nokogiri/internals/XmlDomParserContext.java +16 -25
  22. data/ext/nokogiri/extconf.rb +64 -37
  23. data/ext/nokogiri/xml_document.c +35 -35
  24. data/ext/nokogiri/xml_document_fragment.c +0 -2
  25. data/ext/nokogiri/xml_dtd.c +2 -2
  26. data/ext/nokogiri/xml_encoding_handler.c +25 -11
  27. data/ext/nokogiri/xml_node.c +638 -333
  28. data/ext/nokogiri/xml_reader.c +37 -11
  29. data/ext/nokogiri/xml_xpath_context.c +72 -49
  30. data/ext/nokogiri/xslt_stylesheet.c +107 -9
  31. data/lib/nokogiri/class_resolver.rb +67 -0
  32. data/lib/nokogiri/css/node.rb +9 -8
  33. data/lib/nokogiri/css/parser.rb +360 -341
  34. data/lib/nokogiri/css/parser.y +249 -244
  35. data/lib/nokogiri/css/parser_extras.rb +20 -20
  36. data/lib/nokogiri/css/syntax_error.rb +1 -0
  37. data/lib/nokogiri/css/tokenizer.rb +4 -3
  38. data/lib/nokogiri/css/tokenizer.rex +3 -2
  39. data/lib/nokogiri/css/xpath_visitor.rb +179 -82
  40. data/lib/nokogiri/css.rb +38 -6
  41. data/lib/nokogiri/decorators/slop.rb +8 -7
  42. data/lib/nokogiri/extension.rb +1 -1
  43. data/lib/nokogiri/gumbo.rb +1 -0
  44. data/lib/nokogiri/html.rb +16 -10
  45. data/lib/nokogiri/html4/builder.rb +1 -0
  46. data/lib/nokogiri/html4/document.rb +84 -75
  47. data/lib/nokogiri/html4/document_fragment.rb +11 -7
  48. data/lib/nokogiri/html4/element_description.rb +1 -0
  49. data/lib/nokogiri/html4/element_description_defaults.rb +426 -520
  50. data/lib/nokogiri/html4/entity_lookup.rb +2 -1
  51. data/lib/nokogiri/html4/sax/parser.rb +2 -1
  52. data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
  53. data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
  54. data/lib/nokogiri/html4.rb +11 -5
  55. data/lib/nokogiri/html5/document.rb +24 -10
  56. data/lib/nokogiri/html5/document_fragment.rb +5 -2
  57. data/lib/nokogiri/html5/node.rb +6 -3
  58. data/lib/nokogiri/html5.rb +68 -64
  59. data/lib/nokogiri/jruby/dependencies.rb +10 -9
  60. data/lib/nokogiri/nokogiri.jar +0 -0
  61. data/lib/nokogiri/syntax_error.rb +1 -0
  62. data/lib/nokogiri/version/constant.rb +2 -1
  63. data/lib/nokogiri/version/info.rb +19 -13
  64. data/lib/nokogiri/version.rb +1 -0
  65. data/lib/nokogiri/xml/attr.rb +5 -3
  66. data/lib/nokogiri/xml/attribute_decl.rb +2 -1
  67. data/lib/nokogiri/xml/builder.rb +32 -32
  68. data/lib/nokogiri/xml/cdata.rb +2 -1
  69. data/lib/nokogiri/xml/character_data.rb +1 -0
  70. data/lib/nokogiri/xml/document.rb +139 -103
  71. data/lib/nokogiri/xml/document_fragment.rb +41 -38
  72. data/lib/nokogiri/xml/dtd.rb +3 -2
  73. data/lib/nokogiri/xml/element_content.rb +1 -0
  74. data/lib/nokogiri/xml/element_decl.rb +2 -1
  75. data/lib/nokogiri/xml/entity_decl.rb +3 -2
  76. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  77. data/lib/nokogiri/xml/namespace.rb +2 -0
  78. data/lib/nokogiri/xml/node/save_options.rb +7 -4
  79. data/lib/nokogiri/xml/node.rb +512 -348
  80. data/lib/nokogiri/xml/node_set.rb +46 -54
  81. data/lib/nokogiri/xml/notation.rb +12 -0
  82. data/lib/nokogiri/xml/parse_options.rb +11 -7
  83. data/lib/nokogiri/xml/pp/character_data.rb +8 -6
  84. data/lib/nokogiri/xml/pp/node.rb +24 -26
  85. data/lib/nokogiri/xml/pp.rb +1 -0
  86. data/lib/nokogiri/xml/processing_instruction.rb +2 -1
  87. data/lib/nokogiri/xml/reader.rb +17 -19
  88. data/lib/nokogiri/xml/relax_ng.rb +1 -0
  89. data/lib/nokogiri/xml/sax/document.rb +20 -19
  90. data/lib/nokogiri/xml/sax/parser.rb +36 -34
  91. data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
  92. data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
  93. data/lib/nokogiri/xml/sax.rb +1 -0
  94. data/lib/nokogiri/xml/schema.rb +7 -6
  95. data/lib/nokogiri/xml/searchable.rb +93 -62
  96. data/lib/nokogiri/xml/syntax_error.rb +4 -4
  97. data/lib/nokogiri/xml/text.rb +1 -0
  98. data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
  99. data/lib/nokogiri/xml/xpath.rb +12 -0
  100. data/lib/nokogiri/xml/xpath_context.rb +2 -3
  101. data/lib/nokogiri/xml.rb +3 -3
  102. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  103. data/lib/nokogiri/xslt.rb +21 -13
  104. data/lib/nokogiri.rb +19 -16
  105. data/lib/xsd/xmlparser/nokogiri.rb +25 -24
  106. metadata +102 -30
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
- ENV["RC_ARCHS"] = "" if RUBY_PLATFORM =~ /darwin/
2
+
3
+ # rubocop:disable Style/GlobalVars
4
+
5
+ ENV["RC_ARCHS"] = "" if RUBY_PLATFORM.include?("darwin")
3
6
 
4
7
  require "mkmf"
5
8
  require "rbconfig"
@@ -12,16 +15,14 @@ PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."
12
15
  REQUIRED_LIBXML_VERSION = "2.6.21"
13
16
  RECOMMENDED_LIBXML_VERSION = "2.9.3"
14
17
 
15
- # The gem version constraint in the Rakefile is not respected at install time.
16
- # Keep this version in sync with the one in the Rakefile !
17
- REQUIRED_MINI_PORTILE_VERSION = "~> 2.6.1"
18
+ REQUIRED_MINI_PORTILE_VERSION = "~> 2.8.0" # keep this version in sync with the one in the gemspec
18
19
  REQUIRED_PKG_CONFIG_VERSION = "~> 1.1"
19
20
 
20
21
  # Keep track of what versions of what libraries we build against
21
22
  OTHER_LIBRARY_VERSIONS = {}
22
23
 
23
24
  NOKOGIRI_HELP_MESSAGE = <<~HELP
24
- USAGE: ruby #{$0} [options]
25
+ USAGE: ruby #{$PROGRAM_NAME} [options]
25
26
 
26
27
  Flags that are always valid:
27
28
 
@@ -175,23 +176,23 @@ def config_system_libraries?
175
176
  end
176
177
 
177
178
  def windows?
178
- RbConfig::CONFIG["target_os"] =~ /mingw32|mswin/
179
+ RbConfig::CONFIG["target_os"].match?(/mingw|mswin/)
179
180
  end
180
181
 
181
182
  def solaris?
182
- RbConfig::CONFIG["target_os"] =~ /solaris/
183
+ RbConfig::CONFIG["target_os"].include?("solaris")
183
184
  end
184
185
 
185
186
  def darwin?
186
- RbConfig::CONFIG["target_os"] =~ /darwin/
187
+ RbConfig::CONFIG["target_os"].include?("darwin")
187
188
  end
188
189
 
189
190
  def openbsd?
190
- RbConfig::CONFIG["target_os"] =~ /openbsd/
191
+ RbConfig::CONFIG["target_os"].include?("openbsd")
191
192
  end
192
193
 
193
194
  def aix?
194
- RbConfig::CONFIG["target_os"] =~ /aix/
195
+ RbConfig::CONFIG["target_os"].include?("aix")
195
196
  end
196
197
 
197
198
  def nix?
@@ -210,6 +211,18 @@ def local_have_library(lib, func = nil, headers = nil)
210
211
  have_library(lib, func, headers) || have_library("lib#{lib}", func, headers)
211
212
  end
212
213
 
214
+ def gnome_source
215
+ # As of 2022-02-20, some mirrors have expired SSL certificates. I'm able to retrieve from my home,
216
+ # but whatever host is resolved on the github actions workers see an expired cert.
217
+ #
218
+ # See https://github.com/sparklemotion/nokogiri/runs/5266206403?check_suite_focus=true
219
+ if ENV["NOKOGIRI_USE_CANONICAL_GNOME_SOURCE"]
220
+ "https://download.gnome.org"
221
+ else
222
+ "https://mirror.csclub.uwaterloo.ca/gnome" # old reliable
223
+ end
224
+ end
225
+
213
226
  LOCAL_PACKAGE_RESPONSE = Object.new
214
227
  def LOCAL_PACKAGE_RESPONSE.%(package)
215
228
  package ? "yes: #{package}" : "no"
@@ -284,17 +297,16 @@ ensure
284
297
  end
285
298
 
286
299
  def abort_could_not_find_library(lib)
287
- abort("-----\n#{caller[0]}\n#{lib} is missing. Please locate mkmf.log to investigate how it is failing.\n-----")
300
+ callers = caller(1..2).join("\n")
301
+ abort("-----\n#{callers}\n#{lib} is missing. Please locate mkmf.log to investigate how it is failing.\n-----")
288
302
  end
289
303
 
290
- def chdir_for_build
304
+ def chdir_for_build(&block)
291
305
  # When using rake-compiler-dock on Windows, the underlying Virtualbox shared
292
306
  # folders don't support symlinks, but libiconv expects it for a build on
293
307
  # Linux. We work around this limitation by using the temp dir for cooking.
294
- build_dir = ENV["RCD_HOST_RUBY_PLATFORM"].to_s =~ /mingw|mswin|cygwin/ ? "/tmp" : "."
295
- Dir.chdir(build_dir) do
296
- yield
297
- end
308
+ build_dir = /mingw|mswin|cygwin/.match?(ENV["RCD_HOST_RUBY_PLATFORM"].to_s) ? "/tmp" : "."
309
+ Dir.chdir(build_dir, &block)
298
310
  end
299
311
 
300
312
  def sh_export_path(path)
@@ -402,9 +414,9 @@ def iconv_configure_flags
402
414
  abort_could_not_find_library("libiconv")
403
415
  end
404
416
 
405
- def process_recipe(name, version, static_p, cross_p, cacheable_p=true)
417
+ def process_recipe(name, version, static_p, cross_p, cacheable_p = true)
406
418
  require "rubygems"
407
- gem("mini_portile2", REQUIRED_MINI_PORTILE_VERSION)
419
+ gem("mini_portile2", REQUIRED_MINI_PORTILE_VERSION) # gemspec is not respected at install time
408
420
  require "mini_portile2"
409
421
  message("Using mini_portile version #{MiniPortile::VERSION}\n")
410
422
 
@@ -413,9 +425,13 @@ def process_recipe(name, version, static_p, cross_p, cacheable_p=true)
413
425
  end
414
426
 
415
427
  MiniPortile.new(name, version).tap do |recipe|
428
+ def recipe.port_path
429
+ "#{@target}/#{RUBY_PLATFORM}/#{@name}/#{@version}"
430
+ end
431
+
416
432
  recipe.target = File.join(PACKAGE_ROOT_DIR, "ports") if cacheable_p
417
- # Prefer host_alias over host in order to use i586-mingw32msvc as
418
- # correct compiler prefix for cross build, but use host if not set.
433
+ # Prefer host_alias over host in order to use the correct compiler prefix for cross build, but
434
+ # use host if not set.
419
435
  recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
420
436
  recipe.configure_options << "--libdir=#{File.join(recipe.path, "lib")}"
421
437
 
@@ -462,7 +478,7 @@ def process_recipe(name, version, static_p, cross_p, cacheable_p=true)
462
478
  end
463
479
 
464
480
  if RbConfig::CONFIG["target_cpu"] == "universal"
465
- %w[CFLAGS LDFLAGS].each do |key|
481
+ ["CFLAGS", "LDFLAGS"].each do |key|
466
482
  unless env[key].include?("-arch")
467
483
  env[key] = concat_flags(env[key], RbConfig::CONFIG["ARCH_FLAG"])
468
484
  end
@@ -473,7 +489,7 @@ def process_recipe(name, version, static_p, cross_p, cacheable_p=true)
473
489
  "#{key}=#{value.strip}"
474
490
  end
475
491
 
476
- checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
492
+ checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{RUBY_PLATFORM}.installed"
477
493
  if File.exist?(checkpoint) && !recipe.source_directory
478
494
  message("Building Nokogiri with a packaged version of #{name}-#{version}.\n")
479
495
  else
@@ -487,7 +503,7 @@ def process_recipe(name, version, static_p, cross_p, cacheable_p=true)
487
503
  message("The following patches are being applied:\n")
488
504
 
489
505
  recipe.patch_files.each do |patch|
490
- message(" - %s\n" % File.basename(patch))
506
+ message(format(" - %s\n", File.basename(patch)))
491
507
  end
492
508
  end
493
509
 
@@ -508,6 +524,7 @@ def process_recipe(name, version, static_p, cross_p, cacheable_p=true)
508
524
 
509
525
  EOM
510
526
 
527
+ pp(recipe.files)
511
528
  chdir_for_build { recipe.cook }
512
529
  FileUtils.touch(checkpoint)
513
530
  end
@@ -656,7 +673,7 @@ else
656
673
  if cross_build_p || windows?
657
674
  zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
658
675
  recipe.files = [{
659
- url: "http://zlib.net/fossils/#{recipe.name}-#{recipe.version}.tar.gz",
676
+ url: "https://zlib.net/fossils/#{recipe.name}-#{recipe.version}.tar.gz",
660
677
  sha256: dependencies["zlib"]["sha256"],
661
678
  }]
662
679
  if windows?
@@ -700,7 +717,7 @@ else
700
717
  end
701
718
 
702
719
  def compile
703
- if host =~ /darwin/
720
+ if /darwin/.match?(host)
704
721
  execute("compile", "make AR=#{host}-libtool")
705
722
  else
706
723
  super
@@ -714,10 +731,13 @@ else
714
731
  libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p,
715
732
  cross_build_p) do |recipe|
716
733
  recipe.files = [{
717
- url: "http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
734
+ url: "https://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
718
735
  sha256: dependencies["libiconv"]["sha256"],
719
736
  }]
720
737
 
738
+ # The libiconv configure script doesn't accept "arm64" host string but "aarch64"
739
+ recipe.host = recipe.host.gsub("arm64-apple-darwin", "aarch64-apple-darwin")
740
+
721
741
  cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
722
742
 
723
743
  recipe.configure_options += [
@@ -741,12 +761,21 @@ else
741
761
  Tools" to open the developer site, download the installer for your OS
742
762
  version and run it.
743
763
  -----
744
- EOM
764
+ EOM
745
765
  end
746
766
 
747
- unless windows?
748
- preserving_globals { local_have_library("z", "gzdopen", "zlib.h") } ||
749
- abort("zlib is missing; necessary for building libxml2")
767
+ if zlib_recipe
768
+ append_cppflags("-I#{zlib_recipe.path}/include")
769
+ $LIBPATH = ["#{zlib_recipe.path}/lib"] | $LIBPATH
770
+ ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "z",
771
+ headers: "zlib.h", func: "gzdopen")
772
+ end
773
+
774
+ if libiconv_recipe
775
+ append_cppflags("-I#{libiconv_recipe.path}/include")
776
+ $LIBPATH = ["#{libiconv_recipe.path}/lib"] | $LIBPATH
777
+ ensure_package_configuration(opt: "iconv", pc: "iconv", lib: "iconv",
778
+ headers: "iconv.h", func: "iconv_open")
750
779
  end
751
780
 
752
781
  libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"]["version"], static_p, cross_build_p) do |recipe|
@@ -754,8 +783,9 @@ else
754
783
  if source_dir
755
784
  recipe.source_directory = source_dir
756
785
  else
786
+ minor_version = Gem::Version.new(recipe.version).segments.take(2).join(".")
757
787
  recipe.files = [{
758
- url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
788
+ url: "#{gnome_source}/sources/libxml2/#{minor_version}/#{recipe.name}-#{recipe.version}.tar.xz",
759
789
  sha256: dependencies["libxml2"]["sha256"],
760
790
  }]
761
791
  recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", "libxml2", "*.patch")].sort
@@ -765,7 +795,6 @@ else
765
795
 
766
796
  if zlib_recipe
767
797
  recipe.configure_options << "--with-zlib=#{zlib_recipe.path}"
768
- cflags = concat_flags(cflags, "-I#{zlib_recipe.path}/include")
769
798
  end
770
799
 
771
800
  if libiconv_recipe
@@ -803,8 +832,9 @@ else
803
832
  if source_dir
804
833
  recipe.source_directory = source_dir
805
834
  else
835
+ minor_version = Gem::Version.new(recipe.version).segments.take(2).join(".")
806
836
  recipe.files = [{
807
- url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
837
+ url: "#{gnome_source}/sources/libxslt/#{minor_version}/#{recipe.name}-#{recipe.version}.tar.xz",
808
838
  sha256: dependencies["libxslt"]["sha256"],
809
839
  }]
810
840
  recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", "libxslt", "*.patch")].sort
@@ -834,9 +864,6 @@ else
834
864
  append_cppflags("-DNOKOGIRI_PACKAGED_LIBRARIES")
835
865
  append_cppflags("-DNOKOGIRI_PRECOMPILED_LIBRARIES") if cross_build_p
836
866
 
837
- $LIBPATH = ["#{zlib_recipe.path}/lib"] | $LIBPATH if zlib_recipe
838
- $LIBPATH = ["#{libiconv_recipe.path}/lib"] | $LIBPATH if libiconv_recipe
839
-
840
867
  $libs = $libs.shellsplit.tap do |libs|
841
868
  [libxml2_recipe, libxslt_recipe].each do |recipe|
842
869
  libname = recipe.name[/\Alib(.+)\z/, 1]
@@ -929,7 +956,7 @@ libgumbo_recipe = process_recipe("libgumbo", "1.0.0-nokogiri", static_p, cross_b
929
956
 
930
957
  env = { "CC" => gcc_cmd, "CFLAGS" => cflags }
931
958
  if config_cross_build?
932
- if host =~ /darwin/
959
+ if /darwin/.match?(host)
933
960
  env["AR"] = "#{host}-libtool"
934
961
  env["ARFLAGS"] = "-o"
935
962
  else
@@ -533,59 +533,59 @@ block_caller(void *ctx, xmlNodePtr c_node, xmlNodePtr c_parent_node)
533
533
  static VALUE
534
534
  rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
535
535
  {
536
- VALUE mode;
537
- VALUE incl_ns;
538
- VALUE with_comments;
539
- xmlChar **ns;
540
- long ns_len, i;
536
+ VALUE rb_mode;
537
+ VALUE rb_namespaces;
538
+ VALUE rb_comments_p;
539
+ xmlChar **c_namespaces;
541
540
 
542
- xmlDocPtr doc;
543
- xmlOutputBufferPtr buf;
544
- xmlC14NIsVisibleCallback cb = NULL;
545
- void *ctx = NULL;
541
+ xmlDocPtr c_doc;
542
+ xmlOutputBufferPtr c_obuf;
543
+ xmlC14NIsVisibleCallback c_callback_wrapper = NULL;
544
+ void *rb_callback = NULL;
546
545
 
547
546
  VALUE rb_cStringIO;
548
- VALUE io;
547
+ VALUE rb_io;
549
548
 
550
- rb_scan_args(argc, argv, "03", &mode, &incl_ns, &with_comments);
549
+ rb_scan_args(argc, argv, "03", &rb_mode, &rb_namespaces, &rb_comments_p);
550
+ if (!NIL_P(rb_mode)) { Check_Type(rb_mode, T_FIXNUM); }
551
+ if (!NIL_P(rb_namespaces)) { Check_Type(rb_namespaces, T_ARRAY); }
551
552
 
552
- Data_Get_Struct(self, xmlDoc, doc);
553
+ Data_Get_Struct(self, xmlDoc, c_doc);
553
554
 
554
555
  rb_cStringIO = rb_const_get_at(rb_cObject, rb_intern("StringIO"));
555
- io = rb_class_new_instance(0, 0, rb_cStringIO);
556
- buf = xmlAllocOutputBuffer(NULL);
556
+ rb_io = rb_class_new_instance(0, 0, rb_cStringIO);
557
+ c_obuf = xmlAllocOutputBuffer(NULL);
557
558
 
558
- buf->writecallback = (xmlOutputWriteCallback)noko_io_write;
559
- buf->closecallback = (xmlOutputCloseCallback)noko_io_close;
560
- buf->context = (void *)io;
559
+ c_obuf->writecallback = (xmlOutputWriteCallback)noko_io_write;
560
+ c_obuf->closecallback = (xmlOutputCloseCallback)noko_io_close;
561
+ c_obuf->context = (void *)rb_io;
561
562
 
562
563
  if (rb_block_given_p()) {
563
- cb = block_caller;
564
- ctx = (void *)rb_block_proc();
564
+ c_callback_wrapper = block_caller;
565
+ rb_callback = (void *)rb_block_proc();
565
566
  }
566
567
 
567
- if (NIL_P(incl_ns)) {
568
- ns = NULL;
568
+ if (NIL_P(rb_namespaces)) {
569
+ c_namespaces = NULL;
569
570
  } else {
570
- Check_Type(incl_ns, T_ARRAY);
571
- ns_len = RARRAY_LEN(incl_ns);
572
- ns = calloc((size_t)ns_len + 1, sizeof(xmlChar *));
573
- for (i = 0 ; i < ns_len ; i++) {
574
- VALUE entry = rb_ary_entry(incl_ns, i);
575
- ns[i] = (xmlChar *)StringValueCStr(entry);
571
+ long ns_len = RARRAY_LEN(rb_namespaces);
572
+ c_namespaces = calloc((size_t)ns_len + 1, sizeof(xmlChar *));
573
+ for (int j = 0 ; j < ns_len ; j++) {
574
+ VALUE entry = rb_ary_entry(rb_namespaces, j);
575
+ c_namespaces[j] = (xmlChar *)StringValueCStr(entry);
576
576
  }
577
577
  }
578
578
 
579
+ xmlC14NExecute(c_doc, c_callback_wrapper, rb_callback,
580
+ (int)(NIL_P(rb_mode) ? 0 : NUM2INT(rb_mode)),
581
+ c_namespaces,
582
+ (int)RTEST(rb_comments_p),
583
+ c_obuf);
579
584
 
580
- xmlC14NExecute(doc, cb, ctx,
581
- (int)(NIL_P(mode) ? 0 : NUM2INT(mode)),
582
- ns,
583
- (int) RTEST(with_comments),
584
- buf);
585
-
586
- xmlOutputBufferClose(buf);
585
+ free(c_namespaces);
586
+ xmlOutputBufferClose(c_obuf);
587
587
 
588
- return rb_funcall(io, rb_intern("string"), 0);
588
+ return rb_funcall(rb_io, rb_intern("string"), 0);
589
589
  }
590
590
 
591
591
  VALUE
@@ -28,8 +28,6 @@ new (int argc, VALUE *argv, VALUE klass)
28
28
  rb_node = noko_xml_node_wrap(klass, node);
29
29
  rb_obj_call_init(rb_node, argc, argv);
30
30
 
31
- if (rb_block_given_p()) { rb_yield(rb_node); }
32
-
33
31
  return rb_node;
34
32
  }
35
33
 
@@ -57,9 +57,9 @@ entities(VALUE self)
57
57
 
58
58
  /*
59
59
  * call-seq:
60
- * notations
60
+ * notations() → Hash<name(String)⇒Notation>
61
61
  *
62
- * Get a hash of the notations for this DTD.
62
+ * [Returns] All the notations for this DTD in a Hash of Notation +name+ to Notation.
63
63
  */
64
64
  static VALUE
65
65
  notations(VALUE self)
@@ -3,70 +3,82 @@
3
3
  VALUE cNokogiriEncodingHandler;
4
4
 
5
5
 
6
+ static void
7
+ _xml_encoding_handler_dealloc(xmlCharEncodingHandlerPtr c_handler)
8
+ {
9
+ /* make sure iconv handlers are cleaned up and freed */
10
+ xmlCharEncCloseFunc(c_handler);
11
+ }
12
+
13
+
6
14
  /*
7
15
  * call-seq: Nokogiri::EncodingHandler.[](name)
8
16
  *
9
17
  * Get the encoding handler for +name+
10
18
  */
11
19
  static VALUE
12
- get(VALUE klass, VALUE key)
20
+ rb_xml_encoding_handler_s_get(VALUE klass, VALUE key)
13
21
  {
14
22
  xmlCharEncodingHandlerPtr handler;
15
23
 
16
24
  handler = xmlFindCharEncodingHandler(StringValueCStr(key));
17
25
  if (handler) {
18
- return Data_Wrap_Struct(klass, NULL, NULL, handler);
26
+ return Data_Wrap_Struct(klass, NULL, _xml_encoding_handler_dealloc, handler);
19
27
  }
20
28
 
21
29
  return Qnil;
22
30
  }
23
31
 
32
+
24
33
  /*
25
34
  * call-seq: Nokogiri::EncodingHandler.delete(name)
26
35
  *
27
36
  * Delete the encoding alias named +name+
28
37
  */
29
38
  static VALUE
30
- delete (VALUE klass, VALUE name)
39
+ rb_xml_encoding_handler_s_delete(VALUE klass, VALUE name)
31
40
  {
32
41
  if (xmlDelEncodingAlias(StringValueCStr(name))) { return Qnil; }
33
42
 
34
43
  return Qtrue;
35
44
  }
36
45
 
46
+
37
47
  /*
38
48
  * call-seq: Nokogiri::EncodingHandler.alias(from, to)
39
49
  *
40
50
  * Alias encoding handler with name +from+ to name +to+
41
51
  */
42
52
  static VALUE
43
- alias(VALUE klass, VALUE from, VALUE to)
53
+ rb_xml_encoding_handler_s_alias(VALUE klass, VALUE from, VALUE to)
44
54
  {
45
55
  xmlAddEncodingAlias(StringValueCStr(from), StringValueCStr(to));
46
56
 
47
57
  return to;
48
58
  }
49
59
 
60
+
50
61
  /*
51
62
  * call-seq: Nokogiri::EncodingHandler.clear_aliases!
52
63
  *
53
64
  * Remove all encoding aliases.
54
65
  */
55
66
  static VALUE
56
- clear_aliases(VALUE klass)
67
+ rb_xml_encoding_handler_s_clear_aliases(VALUE klass)
57
68
  {
58
69
  xmlCleanupEncodingAliases();
59
70
 
60
71
  return klass;
61
72
  }
62
73
 
74
+
63
75
  /*
64
76
  * call-seq: name
65
77
  *
66
78
  * Get the name of this EncodingHandler
67
79
  */
68
80
  static VALUE
69
- name(VALUE self)
81
+ rb_xml_encoding_handler_name(VALUE self)
70
82
  {
71
83
  xmlCharEncodingHandlerPtr handler;
72
84
 
@@ -75,6 +87,7 @@ name(VALUE self)
75
87
  return NOKOGIRI_STR_NEW2(handler->name);
76
88
  }
77
89
 
90
+
78
91
  void
79
92
  noko_init_xml_encoding_handler()
80
93
  {
@@ -82,9 +95,10 @@ noko_init_xml_encoding_handler()
82
95
 
83
96
  rb_undef_alloc_func(cNokogiriEncodingHandler);
84
97
 
85
- rb_define_singleton_method(cNokogiriEncodingHandler, "[]", get, 1);
86
- rb_define_singleton_method(cNokogiriEncodingHandler, "delete", delete, 1);
87
- rb_define_singleton_method(cNokogiriEncodingHandler, "alias", alias, 2);
88
- rb_define_singleton_method(cNokogiriEncodingHandler, "clear_aliases!", clear_aliases, 0);
89
- rb_define_method(cNokogiriEncodingHandler, "name", name, 0);
98
+ rb_define_singleton_method(cNokogiriEncodingHandler, "[]", rb_xml_encoding_handler_s_get, 1);
99
+ rb_define_singleton_method(cNokogiriEncodingHandler, "delete", rb_xml_encoding_handler_s_delete, 1);
100
+ rb_define_singleton_method(cNokogiriEncodingHandler, "alias", rb_xml_encoding_handler_s_alias, 2);
101
+ rb_define_singleton_method(cNokogiriEncodingHandler, "clear_aliases!", rb_xml_encoding_handler_s_clear_aliases, 0);
102
+
103
+ rb_define_method(cNokogiriEncodingHandler, "name", rb_xml_encoding_handler_name, 0);
90
104
  }