nokogiri 1.14.5 → 1.15.0

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -8
  3. data/dependencies.yml +6 -6
  4. data/ext/nokogiri/extconf.rb +66 -22
  5. data/ext/nokogiri/html4_document.c +1 -2
  6. data/ext/nokogiri/html4_element_description.c +19 -14
  7. data/ext/nokogiri/html4_sax_parser_context.c +10 -16
  8. data/ext/nokogiri/html4_sax_push_parser.c +2 -2
  9. data/ext/nokogiri/nokogiri.c +46 -24
  10. data/ext/nokogiri/nokogiri.h +13 -2
  11. data/ext/nokogiri/xml_attr.c +1 -1
  12. data/ext/nokogiri/xml_cdata.c +10 -2
  13. data/ext/nokogiri/xml_comment.c +1 -1
  14. data/ext/nokogiri/xml_document.c +102 -22
  15. data/ext/nokogiri/xml_document_fragment.c +1 -1
  16. data/ext/nokogiri/xml_dtd.c +1 -1
  17. data/ext/nokogiri/xml_element_content.c +32 -29
  18. data/ext/nokogiri/xml_element_decl.c +5 -5
  19. data/ext/nokogiri/xml_encoding_handler.c +12 -4
  20. data/ext/nokogiri/xml_entity_reference.c +1 -1
  21. data/ext/nokogiri/xml_namespace.c +11 -12
  22. data/ext/nokogiri/xml_node.c +7 -7
  23. data/ext/nokogiri/xml_node_set.c +125 -105
  24. data/ext/nokogiri/xml_processing_instruction.c +1 -1
  25. data/ext/nokogiri/xml_reader.c +37 -28
  26. data/ext/nokogiri/xml_relax_ng.c +65 -78
  27. data/ext/nokogiri/xml_sax_parser.c +24 -5
  28. data/ext/nokogiri/xml_sax_parser_context.c +46 -25
  29. data/ext/nokogiri/xml_sax_push_parser.c +29 -8
  30. data/ext/nokogiri/xml_schema.c +90 -116
  31. data/ext/nokogiri/xml_text.c +10 -2
  32. data/ext/nokogiri/xml_xpath_context.c +156 -83
  33. data/ext/nokogiri/xslt_stylesheet.c +103 -50
  34. data/gumbo-parser/src/error.c +8 -4
  35. data/gumbo-parser/src/foreign_attrs.c +13 -14
  36. data/gumbo-parser/src/foreign_attrs.gperf +1 -1
  37. data/gumbo-parser/src/parser.c +13 -0
  38. data/lib/nokogiri/css/xpath_visitor.rb +2 -2
  39. data/lib/nokogiri/extension.rb +1 -1
  40. data/lib/nokogiri/html4/document_fragment.rb +1 -1
  41. data/lib/nokogiri/html4/element_description_defaults.rb +1821 -353
  42. data/lib/nokogiri/html5/document_fragment.rb +1 -1
  43. data/lib/nokogiri/html5/node.rb +5 -0
  44. data/lib/nokogiri/html5.rb +5 -2
  45. data/lib/nokogiri/jruby/nokogiri_jars.rb +3 -3
  46. data/lib/nokogiri/version/constant.rb +1 -1
  47. data/lib/nokogiri/xml/attribute_decl.rb +4 -2
  48. data/lib/nokogiri/xml/document_fragment.rb +1 -1
  49. data/lib/nokogiri/xml/element_content.rb +10 -2
  50. data/lib/nokogiri/xml/element_decl.rb +4 -2
  51. data/lib/nokogiri/xml/entity_decl.rb +4 -2
  52. data/lib/nokogiri/xml/node/save_options.rb +8 -0
  53. data/lib/nokogiri/xml/node.rb +22 -13
  54. data/lib/nokogiri/xml/pp/node.rb +23 -12
  55. data/lib/nokogiri/xml/sax/document.rb +1 -1
  56. data/lib/nokogiri/xml/searchable.rb +18 -10
  57. data/lib/nokogiri/xslt.rb +73 -3
  58. data/lib/nokogiri.rb +12 -4
  59. data/lib/xsd/xmlparser/nokogiri.rb +1 -1
  60. data/patches/libxml2/0010-update-config.guess-and-config.sub-for-libxml2.patch +224 -0
  61. data/patches/libxml2/0011-rip-out-libxml2-s-libc_single_threaded-support.patch +30 -0
  62. data/patches/libxslt/0001-update-config.guess-and-config.sub-for-libxslt.patch +224 -0
  63. data/ports/archives/libxml2-2.11.3.tar.xz +0 -0
  64. data/ports/archives/libxslt-1.1.38.tar.xz +0 -0
  65. metadata +9 -7
  66. data/patches/libxslt/0001-update-automake-files-for-arm64.patch +0 -3037
  67. data/ports/archives/libxml2-2.10.4.tar.xz +0 -0
  68. data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5af6137a33b76407a14ffbc976f989414274eab500081ac9fd885fd32656ad25
4
- data.tar.gz: 7a2f1fae858db5d6f0e2b5eec527e16822fa47e22c152b88c59b8b5d07bc542c
3
+ metadata.gz: cad4c790fb66865a2b47c27345cdb2785c61b9a599490fcbef62150e83078547
4
+ data.tar.gz: da81f866cd1451d0583b8fd376625185052c8d17f7a3b6250c43fec7d906daf8
5
5
  SHA512:
6
- metadata.gz: b6702929520f9c963eb15dd210a3ac2a6a2ce1c310f40226adfc3760e98843efa64a46015e5085da1d72022fbde3213d954539165ce436f0119bc59f60e65253
7
- data.tar.gz: b0182bbc6834b34ac92bfa3ce2d74c7c492a09000062d92248b63e2a93aca9eb5fe5b001313c9c1a31ac27486e2eedf10de200e51e2c454244fa879428b508cb
6
+ metadata.gz: 5b7e4a97225c6a4516fc298a9826d890fd652d1adcd7a2b90e02979e46015114ba9f63d9fdd34b5d398b562a23745386c77ba90165f8e214354a149758b88bfa
7
+ data.tar.gz: a7127084785dbd6761e87d14b57fe17fa338babba7a05e8f724bfeb749b7ce4344681bb9429eca6c9bc6defd27f6238d4c785a0657656a7d9ca7e531926d1423
data/Gemfile CHANGED
@@ -20,19 +20,20 @@ group :development do
20
20
  gem "rexical", "= 1.0.7"
21
21
 
22
22
  # tests
23
- gem "minitest", "5.17.0"
24
- gem "minitest-reporters", "= 1.5.0"
25
- gem "ruby_memcheck", "1.2.0" unless RUBY_PLATFORM == "java"
26
- gem "simplecov", "= 0.21.2"
23
+ gem "minitest", "5.18.0"
24
+ gem "minitest-reporters", "1.6.0"
25
+ gem "ruby_memcheck", git: "https://github.com/flavorjones/ruby_memcheck", ref: "flavorjones-nokogiri-huge-parse-option"
27
26
  gem "rubyzip", "~> 2.3.2"
27
+ gem "simplecov", "= 0.21.2"
28
28
 
29
29
  # rubocop
30
30
  if Gem::Requirement.new("~> 3.0").satisfied_by?(Gem::Version.new(RUBY_VERSION))
31
- gem "rubocop", "1.44.1"
32
- gem "rubocop-minitest", "0.27.0"
33
- gem "rubocop-performance", "1.15.2"
31
+ gem "rubocop", "1.50.2"
32
+ gem "rubocop-minitest", "0.31.0"
33
+ gem "rubocop-packaging", "0.5.2"
34
+ gem "rubocop-performance", "1.17.1"
34
35
  gem "rubocop-rake", "= 0.6.0"
35
- gem "rubocop-shopify", "2.10.1"
36
+ gem "rubocop-shopify", "2.13.0"
36
37
  end
37
38
  end
38
39
 
data/dependencies.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  libxml2:
2
- version: "2.10.4"
3
- sha256: "ed0c91c5845008f1936739e4eee2035531c1c94742c6541f44ee66d885948d45"
4
- # sha-256 hash provided in https://download.gnome.org/sources/libxml2/2.10/libxml2-2.10.4.sha256sum
2
+ version: "2.11.3"
3
+ sha256: "f1acae1664bda006cd81bfc238238217043d586d06659d5c0e3d1bcebe040870"
4
+ # sha-256 hash provided in https://download.gnome.org/sources/libxml2/2.11/libxml2-2.11.3.sha256sum
5
5
 
6
6
  libxslt:
7
- version: "1.1.37"
8
- sha256: "3a4b27dc8027ccd6146725950336f1ec520928f320f144eb5fa7990ae6123ab4"
9
- # sha-256 hash provided in https://download.gnome.org/sources/libxslt/1.1/libxslt-1.1.37.sha256sum
7
+ version: "1.1.38"
8
+ sha256: "1f32450425819a09acaff2ab7a5a7f8a2ec7956e505d7beeb45e843d0e1ecab1"
9
+ # sha-256 hash provided in https://download.gnome.org/sources/libxslt/1.1/libxslt-1.1.38.sha256sum
10
10
 
11
11
  zlib:
12
12
  version: "1.2.13"
@@ -15,7 +15,7 @@ PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."
15
15
  REQUIRED_LIBXML_VERSION = "2.6.21"
16
16
  RECOMMENDED_LIBXML_VERSION = "2.9.3"
17
17
 
18
- REQUIRED_MINI_PORTILE_VERSION = "~> 2.8.0" # keep this version in sync with the one in the gemspec
18
+ REQUIRED_MINI_PORTILE_VERSION = "~> 2.8.2" # keep this version in sync with the one in the gemspec
19
19
  REQUIRED_PKG_CONFIG_VERSION = "~> 1.1"
20
20
 
21
21
  # Keep track of what versions of what libraries we build against
@@ -229,7 +229,7 @@ def gnome_source
229
229
  if ENV["NOKOGIRI_USE_CANONICAL_GNOME_SOURCE"]
230
230
  "https://download.gnome.org"
231
231
  else
232
- "https://mirror.csclub.uwaterloo.ca/gnome" # old reliable
232
+ "https://muug.ca/mirror/gnome" # old reliable
233
233
  end
234
234
  end
235
235
 
@@ -372,7 +372,7 @@ def try_link_iconv(using = nil)
372
372
  preserving_globals do
373
373
  yield if block_given?
374
374
 
375
- try_link(<<~'SRC', opt)
375
+ try_link(<<~SRC, opt)
376
376
  #include <stdlib.h>
377
377
  #include <iconv.h>
378
378
  int main(void)
@@ -695,14 +695,34 @@ append_cppflags(' "-Idummypath"') if windows?
695
695
 
696
696
  if config_system_libraries?
697
697
  message "Building nokogiri using system libraries.\n"
698
- ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "z",
699
- headers: "zlib.h", func: "gzdopen")
700
- ensure_package_configuration(opt: "xml2", pc: "libxml-2.0", lib: "xml2",
701
- headers: "libxml/parser.h", func: "xmlParseDoc")
702
- ensure_package_configuration(opt: "xslt", pc: "libxslt", lib: "xslt",
703
- headers: "libxslt/xslt.h", func: "xsltParseStylesheetDoc")
704
- ensure_package_configuration(opt: "exslt", pc: "libexslt", lib: "exslt",
705
- headers: "libexslt/exslt.h", func: "exsltFuncRegister")
698
+ ensure_package_configuration(
699
+ opt: "zlib",
700
+ pc: "zlib",
701
+ lib: "z",
702
+ headers: "zlib.h",
703
+ func: "gzdopen",
704
+ )
705
+ ensure_package_configuration(
706
+ opt: "xml2",
707
+ pc: "libxml-2.0",
708
+ lib: "xml2",
709
+ headers: "libxml/parser.h",
710
+ func: "xmlParseDoc",
711
+ )
712
+ ensure_package_configuration(
713
+ opt: "xslt",
714
+ pc: "libxslt",
715
+ lib: "xslt",
716
+ headers: "libxslt/xslt.h",
717
+ func: "xsltParseStylesheetDoc",
718
+ )
719
+ ensure_package_configuration(
720
+ opt: "exslt",
721
+ pc: "libexslt",
722
+ lib: "exslt",
723
+ headers: "libexslt/exslt.h",
724
+ func: "exsltFuncRegister",
725
+ )
706
726
 
707
727
  have_libxml_headers?(REQUIRED_LIBXML_VERSION) ||
708
728
  abort("ERROR: libxml2 version #{REQUIRED_LIBXML_VERSION} or later is required!")
@@ -785,8 +805,12 @@ else
785
805
  end
786
806
 
787
807
  unless nix?
788
- libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p,
789
- cross_build_p) do |recipe|
808
+ libiconv_recipe = process_recipe(
809
+ "libiconv",
810
+ dependencies["libiconv"]["version"],
811
+ static_p,
812
+ cross_build_p,
813
+ ) do |recipe|
790
814
  recipe.files = [{
791
815
  url: "https://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
792
816
  sha256: dependencies["libiconv"]["sha256"],
@@ -824,15 +848,25 @@ else
824
848
  if zlib_recipe
825
849
  append_cppflags("-I#{zlib_recipe.path}/include")
826
850
  $LIBPATH = ["#{zlib_recipe.path}/lib"] | $LIBPATH
827
- ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "z",
828
- headers: "zlib.h", func: "gzdopen")
851
+ ensure_package_configuration(
852
+ opt: "zlib",
853
+ pc: "zlib",
854
+ lib: "z",
855
+ headers: "zlib.h",
856
+ func: "gzdopen",
857
+ )
829
858
  end
830
859
 
831
860
  if libiconv_recipe
832
861
  append_cppflags("-I#{libiconv_recipe.path}/include")
833
862
  $LIBPATH = ["#{libiconv_recipe.path}/lib"] | $LIBPATH
834
- ensure_package_configuration(opt: "iconv", pc: "iconv", lib: "iconv",
835
- headers: "iconv.h", func: "iconv_open")
863
+ ensure_package_configuration(
864
+ opt: "iconv",
865
+ pc: "iconv",
866
+ lib: "iconv",
867
+ headers: "iconv.h",
868
+ func: "iconv_open",
869
+ )
836
870
  end
837
871
 
838
872
  libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"]["version"], static_p, cross_build_p) do |recipe|
@@ -848,8 +882,13 @@ else
848
882
  recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", "libxml2", "*.patch")].sort
849
883
  end
850
884
 
885
+ cppflags = concat_flags(ENV["CPPFLAGS"])
851
886
  cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
852
887
 
888
+ if cross_build_p
889
+ cppflags = concat_flags(cppflags, "-DNOKOGIRI_PRECOMPILED_LIBRARIES")
890
+ end
891
+
853
892
  if zlib_recipe
854
893
  recipe.configure_options << "--with-zlib=#{zlib_recipe.path}"
855
894
  end
@@ -880,6 +919,7 @@ else
880
919
  "--with-c14n",
881
920
  "--with-debug",
882
921
  "--with-threads",
922
+ "CPPFLAGS=#{cppflags}",
883
923
  "CFLAGS=#{cflags}",
884
924
  ]
885
925
  end
@@ -1023,7 +1063,7 @@ libgumbo_recipe = process_recipe("libgumbo", "1.0.0-nokogiri", static_p, cross_b
1023
1063
 
1024
1064
  env = { "CC" => gcc_cmd, "CFLAGS" => cflags }
1025
1065
  if config_cross_build?
1026
- if /darwin/.match?(host)
1066
+ if host.include?("darwin")
1027
1067
  env["AR"] = "#{host}-libtool"
1028
1068
  env["ARFLAGS"] = "-o"
1029
1069
  else
@@ -1057,12 +1097,16 @@ unless config_system_libraries?
1057
1097
  if cross_build_p
1058
1098
  # When precompiling native gems, copy packaged libraries' headers to ext/nokogiri/include
1059
1099
  # These are packaged up by the cross-compiling callback in the ExtensionTask
1060
- copy_packaged_libraries_headers(to_path: File.join(PACKAGE_ROOT_DIR, "ext/nokogiri/include"),
1061
- from_recipes: [libxml2_recipe, libxslt_recipe])
1100
+ copy_packaged_libraries_headers(
1101
+ to_path: File.join(PACKAGE_ROOT_DIR, "ext/nokogiri/include"),
1102
+ from_recipes: [libxml2_recipe, libxslt_recipe],
1103
+ )
1062
1104
  else
1063
1105
  # When compiling during installation, install packaged libraries' header files into ext/nokogiri/include
1064
- copy_packaged_libraries_headers(to_path: "include",
1065
- from_recipes: [libxml2_recipe, libxslt_recipe])
1106
+ copy_packaged_libraries_headers(
1107
+ to_path: "include",
1108
+ from_recipes: [libxml2_recipe, libxslt_recipe],
1109
+ )
1066
1110
  $INSTALLFILES << ["include/**/*.h", "$(rubylibdir)"]
1067
1111
  end
1068
1112
  end
@@ -144,8 +144,7 @@ rb_html_document_s_read_memory(VALUE klass, VALUE rb_html, VALUE rb_url, VALUE r
144
144
  static VALUE
145
145
  rb_html_document_type(VALUE self)
146
146
  {
147
- htmlDocPtr doc;
148
- Data_Get_Struct(self, xmlDoc, doc);
147
+ htmlDocPtr doc = noko_xml_document_unwrap(self);
149
148
  return INT2NUM(doc->type);
150
149
  }
151
150
 
@@ -1,5 +1,10 @@
1
1
  #include <nokogiri.h>
2
2
 
3
+ static const rb_data_type_t html4_element_description_type = {
4
+ .wrap_struct_name = "Nokogiri::HTML4::ElementDescription",
5
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
6
+ };
7
+
3
8
  VALUE cNokogiriHtml4ElementDescription ;
4
9
 
5
10
  /*
@@ -15,7 +20,7 @@ required_attributes(VALUE self)
15
20
  VALUE list;
16
21
  int i;
17
22
 
18
- Data_Get_Struct(self, htmlElemDesc, description);
23
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
19
24
 
20
25
  list = rb_ary_new();
21
26
 
@@ -41,7 +46,7 @@ deprecated_attributes(VALUE self)
41
46
  VALUE list;
42
47
  int i;
43
48
 
44
- Data_Get_Struct(self, htmlElemDesc, description);
49
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
45
50
 
46
51
  list = rb_ary_new();
47
52
 
@@ -67,7 +72,7 @@ optional_attributes(VALUE self)
67
72
  VALUE list;
68
73
  int i;
69
74
 
70
- Data_Get_Struct(self, htmlElemDesc, description);
75
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
71
76
 
72
77
  list = rb_ary_new();
73
78
 
@@ -90,7 +95,7 @@ static VALUE
90
95
  default_sub_element(VALUE self)
91
96
  {
92
97
  const htmlElemDesc *description;
93
- Data_Get_Struct(self, htmlElemDesc, description);
98
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
94
99
 
95
100
  if (description->defaultsubelt) {
96
101
  return NOKOGIRI_STR_NEW2(description->defaultsubelt);
@@ -112,7 +117,7 @@ sub_elements(VALUE self)
112
117
  VALUE list;
113
118
  int i;
114
119
 
115
- Data_Get_Struct(self, htmlElemDesc, description);
120
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
116
121
 
117
122
  list = rb_ary_new();
118
123
 
@@ -135,7 +140,7 @@ static VALUE
135
140
  description(VALUE self)
136
141
  {
137
142
  const htmlElemDesc *description;
138
- Data_Get_Struct(self, htmlElemDesc, description);
143
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
139
144
 
140
145
  return NOKOGIRI_STR_NEW2(description->desc);
141
146
  }
@@ -150,7 +155,7 @@ static VALUE
150
155
  inline_eh(VALUE self)
151
156
  {
152
157
  const htmlElemDesc *description;
153
- Data_Get_Struct(self, htmlElemDesc, description);
158
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
154
159
 
155
160
  if (description->isinline) { return Qtrue; }
156
161
  return Qfalse;
@@ -166,7 +171,7 @@ static VALUE
166
171
  deprecated_eh(VALUE self)
167
172
  {
168
173
  const htmlElemDesc *description;
169
- Data_Get_Struct(self, htmlElemDesc, description);
174
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
170
175
 
171
176
  if (description->depr) { return Qtrue; }
172
177
  return Qfalse;
@@ -182,7 +187,7 @@ static VALUE
182
187
  empty_eh(VALUE self)
183
188
  {
184
189
  const htmlElemDesc *description;
185
- Data_Get_Struct(self, htmlElemDesc, description);
190
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
186
191
 
187
192
  if (description->empty) { return Qtrue; }
188
193
  return Qfalse;
@@ -198,7 +203,7 @@ static VALUE
198
203
  save_end_tag_eh(VALUE self)
199
204
  {
200
205
  const htmlElemDesc *description;
201
- Data_Get_Struct(self, htmlElemDesc, description);
206
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
202
207
 
203
208
  if (description->saveEndTag) { return Qtrue; }
204
209
  return Qfalse;
@@ -214,7 +219,7 @@ static VALUE
214
219
  implied_end_tag_eh(VALUE self)
215
220
  {
216
221
  const htmlElemDesc *description;
217
- Data_Get_Struct(self, htmlElemDesc, description);
222
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
218
223
 
219
224
  if (description->endTag) { return Qtrue; }
220
225
  return Qfalse;
@@ -230,7 +235,7 @@ static VALUE
230
235
  implied_start_tag_eh(VALUE self)
231
236
  {
232
237
  const htmlElemDesc *description;
233
- Data_Get_Struct(self, htmlElemDesc, description);
238
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
234
239
 
235
240
  if (description->startTag) { return Qtrue; }
236
241
  return Qfalse;
@@ -246,7 +251,7 @@ static VALUE
246
251
  name(VALUE self)
247
252
  {
248
253
  const htmlElemDesc *description;
249
- Data_Get_Struct(self, htmlElemDesc, description);
254
+ TypedData_Get_Struct(self, htmlElemDesc, &html4_element_description_type, description);
250
255
 
251
256
  if (NULL == description->name) { return Qnil; }
252
257
  return NOKOGIRI_STR_NEW2(description->name);
@@ -266,7 +271,7 @@ get_description(VALUE klass, VALUE tag_name)
266
271
  );
267
272
 
268
273
  if (NULL == description) { return Qnil; }
269
- return Data_Wrap_Struct(klass, 0, 0, DISCARD_CONST_QUAL(void *, description));
274
+ return TypedData_Wrap_Struct(klass, &html4_element_description_type, DISCARD_CONST_QUAL(void *, description));
270
275
  }
271
276
 
272
277
  void
@@ -2,13 +2,6 @@
2
2
 
3
3
  VALUE cNokogiriHtml4SaxParserContext ;
4
4
 
5
- static void
6
- deallocate(xmlParserCtxtPtr ctxt)
7
- {
8
- ctxt->sax = NULL;
9
- htmlFreeParserCtxt(ctxt);
10
- }
11
-
12
5
  static VALUE
13
6
  parse_memory(VALUE klass, VALUE data, VALUE encoding)
14
7
  {
@@ -38,7 +31,7 @@ parse_memory(VALUE klass, VALUE data, VALUE encoding)
38
31
  }
39
32
  }
40
33
 
41
- return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
34
+ return noko_xml_sax_parser_context_wrap(klass, ctxt);
42
35
  }
43
36
 
44
37
  static VALUE
@@ -48,7 +41,13 @@ parse_file(VALUE klass, VALUE filename, VALUE encoding)
48
41
  StringValueCStr(filename),
49
42
  StringValueCStr(encoding)
50
43
  );
51
- return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
44
+
45
+ if (ctxt->sax) {
46
+ xmlFree(ctxt->sax);
47
+ ctxt->sax = NULL;
48
+ }
49
+
50
+ return noko_xml_sax_parser_context_wrap(klass, ctxt);
52
51
  }
53
52
 
54
53
  static VALUE
@@ -82,13 +81,8 @@ parse_with(VALUE self, VALUE sax_handler)
82
81
  rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::SAX::Parser");
83
82
  }
84
83
 
85
- Data_Get_Struct(self, htmlParserCtxt, ctxt);
86
- Data_Get_Struct(sax_handler, htmlSAXHandler, sax);
87
-
88
- /* Free the sax handler since we'll assign our own */
89
- if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) {
90
- xmlFree(ctxt->sax);
91
- }
84
+ ctxt = noko_xml_sax_parser_context_unwrap(self);
85
+ sax = noko_sax_handler_unwrap(sax_handler);
92
86
 
93
87
  ctxt->sax = sax;
94
88
  ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);
@@ -17,7 +17,7 @@ native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
17
17
  int status = 0;
18
18
  libxmlStructuredErrorHandlerState handler_state;
19
19
 
20
- Data_Get_Struct(self, xmlParserCtxt, ctx);
20
+ ctx = noko_xml_sax_push_parser_unwrap(self);
21
21
 
22
22
  if (Qnil != _chunk) {
23
23
  chunk = StringValuePtr(_chunk);
@@ -54,7 +54,7 @@ initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename,
54
54
  htmlParserCtxtPtr ctx;
55
55
  xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
56
56
 
57
- Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
57
+ sax = noko_sax_handler_unwrap(_xml_sax);
58
58
 
59
59
  if (_filename != Qnil) { filename = StringValueCStr(_filename); }
60
60
 
@@ -137,6 +137,48 @@ noko_io_close(void *io)
137
137
  }
138
138
 
139
139
 
140
+ #if defined(_WIN32) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
141
+ # define NOKOGIRI_WINDOWS_DLLS 1
142
+ #else
143
+ # define NOKOGIRI_WINDOWS_DLLS 0
144
+ #endif
145
+
146
+ //
147
+ // | dlls || true | false |
148
+ // | nlmm || | |
149
+ // |-----------++---------+---------|
150
+ // | NULL || default | ruby |
151
+ // | "random" || default | ruby |
152
+ // | "ruby" || ruby | ruby |
153
+ // | "default" || default | default |
154
+ //
155
+ // We choose *not* to use Ruby's memory management functions with windows DLLs because of this
156
+ // issue: https://github.com/sparklemotion/nokogiri/issues/2241
157
+ //
158
+ static void
159
+ set_libxml_memory_management(void)
160
+ {
161
+ const char *nlmm = getenv("NOKOGIRI_LIBXML_MEMORY_MANAGEMENT");
162
+ if (nlmm) {
163
+ if (strcmp(nlmm, "default") == 0) {
164
+ goto libxml_uses_default_memory_management;
165
+ } else if (strcmp(nlmm, "ruby") == 0) {
166
+ goto libxml_uses_ruby_memory_management;
167
+ }
168
+ }
169
+ if (NOKOGIRI_WINDOWS_DLLS) {
170
+ libxml_uses_default_memory_management:
171
+ rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("default"));
172
+ return;
173
+ } else {
174
+ libxml_uses_ruby_memory_management:
175
+ rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("ruby"));
176
+ xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
177
+ return;
178
+ }
179
+ }
180
+
181
+
140
182
  void
141
183
  Init_nokogiri(void)
142
184
  {
@@ -150,6 +192,10 @@ Init_nokogiri(void)
150
192
  mNokogiriXmlXpath = rb_define_module_under(mNokogiriXml, "XPath");
151
193
  mNokogiriXslt = rb_define_module_under(mNokogiri, "XSLT");
152
194
 
195
+ set_libxml_memory_management(); /* must be before any function calls that might invoke xmlInitParser() */
196
+ xmlInitParser();
197
+ exsltRegisterAll();
198
+
153
199
  rb_const_set(mNokogiri, rb_intern("LIBXML_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION));
154
200
  rb_const_set(mNokogiri, rb_intern("LIBXML_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xmlParserVersion));
155
201
 
@@ -182,30 +228,6 @@ Init_nokogiri(void)
182
228
  rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
183
229
  #endif
184
230
 
185
- #if defined(_WIN32) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
186
- /*
187
- * We choose *not* to do use Ruby's memory management functions with windows DLLs because of this
188
- * issue in libxml 2.9.12:
189
- *
190
- * https://github.com/sparklemotion/nokogiri/issues/2241
191
- *
192
- * If the atexit() issue gets fixed in a future version of libxml2, then we may be able to skip
193
- * this config only for the specific libxml2 versions 2.9.12.
194
- *
195
- * Alternatively, now that Ruby has a generational GC, it might be OK to let libxml2 use its
196
- * default memory management functions (recall that this config was introduced to reduce memory
197
- * bloat and allow Ruby to GC more often); but we should *really* test with production workloads
198
- * before making that kind of a potentially-invasive change.
199
- */
200
- rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("default"));
201
- #else
202
- rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("ruby"));
203
- xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
204
- #endif
205
-
206
- xmlInitParser();
207
- exsltRegisterAll();
208
-
209
231
  if (xsltExtModuleFunctionLookup((const xmlChar *)"date-time", EXSLT_DATE_NAMESPACE)) {
210
232
  rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qtrue);
211
233
  } else {
@@ -51,6 +51,7 @@
51
51
  #include <libxslt/xsltconfig.h>
52
52
  #include <libxslt/xsltutils.h>
53
53
  #include <libxslt/transform.h>
54
+ #include <libxslt/imports.h>
54
55
  #include <libxslt/xsltInternals.h>
55
56
 
56
57
  #include <libexslt/exslt.h>
@@ -168,6 +169,7 @@ typedef struct _nokogiriXsltStylesheetTuple {
168
169
 
169
170
  void noko_xml_document_pin_node(xmlNodePtr);
170
171
  void noko_xml_document_pin_namespace(xmlNsPtr, xmlDocPtr);
172
+ int noko_xml_document_has_wrapped_blank_nodes_p(xmlDocPtr c_document);
171
173
 
172
174
  int noko_io_read(void *ctx, char *buffer, int len);
173
175
  int noko_io_write(void *ctx, char *buffer, int len);
@@ -186,12 +188,21 @@ VALUE noko_xml_namespace_wrap_xpath_copy(xmlNsPtr node);
186
188
  VALUE noko_xml_element_content_wrap(VALUE doc, xmlElementContentPtr element);
187
189
 
188
190
  VALUE noko_xml_node_set_wrap(xmlNodeSetPtr node_set, VALUE document) ;
191
+ xmlNodeSetPtr noko_xml_node_set_unwrap(VALUE rb_node_set) ;
189
192
 
190
193
  VALUE noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr doc, int argc, VALUE *argv);
191
194
  VALUE noko_xml_document_wrap(VALUE klass, xmlDocPtr doc);
195
+ xmlDocPtr noko_xml_document_unwrap(VALUE rb_document);
192
196
  NOKOPUBFUN VALUE Nokogiri_wrap_xml_document(VALUE klass,
193
197
  xmlDocPtr doc); /* deprecated. use noko_xml_document_wrap() instead. */
194
198
 
199
+ xmlSAXHandlerPtr noko_sax_handler_unwrap(VALUE rb_sax_handler);
200
+
201
+ xmlParserCtxtPtr noko_xml_sax_push_parser_unwrap(VALUE rb_parser);
202
+
203
+ VALUE noko_xml_sax_parser_context_wrap(VALUE klass, xmlParserCtxtPtr c_context);
204
+ xmlParserCtxtPtr noko_xml_sax_parser_context_unwrap(VALUE rb_context);
205
+
195
206
  #define DOC_RUBY_OBJECT_TEST(x) ((nokogiriTuplePtr)(x->_private))
196
207
  #define DOC_RUBY_OBJECT(x) (((nokogiriTuplePtr)(x->_private))->doc)
197
208
  #define DOC_UNLINKED_NODE_HASH(x) (((nokogiriTuplePtr)(x->_private))->unlinkedNodes)
@@ -207,9 +218,9 @@ NOKOPUBFUN VALUE Nokogiri_wrap_xml_document(VALUE klass,
207
218
  #define DISCARD_CONST_QUAL_XMLCHAR(v) DISCARD_CONST_QUAL(xmlChar *, v)
208
219
 
209
220
  #if HAVE_RB_CATEGORY_WARNING
210
- # define NOKO_WARN_DEPRECATION(message) rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, message)
221
+ # define NOKO_WARN_DEPRECATION(message...) rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, message)
211
222
  #else
212
- # define NOKO_WARN_DEPRECATION(message) rb_warning(message)
223
+ # define NOKO_WARN_DEPRECATION(message...) rb_warning(message)
213
224
  #endif
214
225
 
215
226
  void Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state);
@@ -68,7 +68,7 @@ new (int argc, VALUE *argv, VALUE klass)
68
68
  rb_raise(rb_eArgError, "parameter must be a Nokogiri::XML::Document");
69
69
  }
70
70
 
71
- Noko_Node_Get_Struct(document, xmlDoc, xml_doc);
71
+ xml_doc = noko_xml_document_unwrap(document);
72
72
 
73
73
  node = xmlNewDocProp(
74
74
  xml_doc,
@@ -25,14 +25,22 @@ new (int argc, VALUE *argv, VALUE klass)
25
25
 
26
26
  rb_scan_args(argc, argv, "2*", &doc, &content, &rest);
27
27
 
28
- Noko_Node_Get_Struct(doc, xmlDoc, xml_doc);
28
+ if (rb_obj_is_kind_of(doc, cNokogiriXmlDocument)) {
29
+ xml_doc = noko_xml_document_unwrap(doc);
30
+ } else {
31
+ xmlNodePtr deprecated_node_type_arg;
32
+ // TODO: deprecate allowing Node
33
+ NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to CDATA.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
34
+ Noko_Node_Get_Struct(doc, xmlNode, deprecated_node_type_arg);
35
+ xml_doc = deprecated_node_type_arg->doc;
36
+ }
29
37
 
30
38
  if (!NIL_P(content)) {
31
39
  content_str = (xmlChar *)StringValuePtr(content);
32
40
  content_str_len = RSTRING_LENINT(content);
33
41
  }
34
42
 
35
- node = xmlNewCDataBlock(xml_doc->doc, content_str, content_str_len);
43
+ node = xmlNewCDataBlock(xml_doc, content_str, content_str_len);
36
44
 
37
45
  noko_xml_document_pin_node(node);
38
46
 
@@ -30,7 +30,7 @@ new (int argc, VALUE *argv, VALUE klass)
30
30
  rb_raise(rb_eArgError, "first argument must be a XML::Document or XML::Node");
31
31
  }
32
32
 
33
- Data_Get_Struct(document, xmlDoc, xml_doc);
33
+ xml_doc = noko_xml_document_unwrap(document);
34
34
 
35
35
  node = xmlNewDocComment(
36
36
  xml_doc,