nokogiri 1.14.5-java → 1.15.0-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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -8
  3. data/dependencies.yml +6 -6
  4. data/ext/java/nokogiri/NokogiriService.java +0 -1
  5. data/ext/java/nokogiri/XmlCdata.java +6 -0
  6. data/ext/java/nokogiri/XmlNode.java +14 -5
  7. data/ext/java/nokogiri/XmlSchema.java +5 -0
  8. data/ext/java/nokogiri/XmlText.java +5 -0
  9. data/ext/java/nokogiri/XsltStylesheet.java +5 -20
  10. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +0 -25
  11. data/ext/java/nokogiri/internals/SaveContextVisitor.java +1 -0
  12. data/ext/nokogiri/extconf.rb +66 -22
  13. data/ext/nokogiri/html4_document.c +1 -2
  14. data/ext/nokogiri/html4_element_description.c +19 -14
  15. data/ext/nokogiri/html4_sax_parser_context.c +10 -16
  16. data/ext/nokogiri/html4_sax_push_parser.c +2 -2
  17. data/ext/nokogiri/nokogiri.c +46 -24
  18. data/ext/nokogiri/xml_attr.c +1 -1
  19. data/ext/nokogiri/xml_cdata.c +10 -2
  20. data/ext/nokogiri/xml_comment.c +1 -1
  21. data/ext/nokogiri/xml_document.c +102 -22
  22. data/ext/nokogiri/xml_document_fragment.c +1 -1
  23. data/ext/nokogiri/xml_dtd.c +1 -1
  24. data/ext/nokogiri/xml_element_content.c +32 -29
  25. data/ext/nokogiri/xml_element_decl.c +5 -5
  26. data/ext/nokogiri/xml_encoding_handler.c +12 -4
  27. data/ext/nokogiri/xml_entity_reference.c +1 -1
  28. data/ext/nokogiri/xml_namespace.c +11 -12
  29. data/ext/nokogiri/xml_node.c +7 -7
  30. data/ext/nokogiri/xml_node_set.c +125 -105
  31. data/ext/nokogiri/xml_processing_instruction.c +1 -1
  32. data/ext/nokogiri/xml_reader.c +37 -28
  33. data/ext/nokogiri/xml_relax_ng.c +65 -78
  34. data/ext/nokogiri/xml_sax_parser.c +24 -5
  35. data/ext/nokogiri/xml_sax_parser_context.c +46 -25
  36. data/ext/nokogiri/xml_sax_push_parser.c +29 -8
  37. data/ext/nokogiri/xml_schema.c +90 -116
  38. data/ext/nokogiri/xml_text.c +10 -2
  39. data/ext/nokogiri/xml_xpath_context.c +156 -83
  40. data/ext/nokogiri/xslt_stylesheet.c +103 -50
  41. data/lib/nokogiri/css/xpath_visitor.rb +2 -2
  42. data/lib/nokogiri/extension.rb +1 -1
  43. data/lib/nokogiri/html4/document_fragment.rb +1 -1
  44. data/lib/nokogiri/html4/element_description_defaults.rb +1821 -353
  45. data/lib/nokogiri/html5/document_fragment.rb +1 -1
  46. data/lib/nokogiri/html5/node.rb +5 -0
  47. data/lib/nokogiri/html5.rb +5 -2
  48. data/lib/nokogiri/jruby/nokogiri_jars.rb +3 -3
  49. data/lib/nokogiri/jruby/org/nokogiri/nekodtd/0.1.11.noko1/nekodtd-0.1.11.noko1.jar +0 -0
  50. data/lib/nokogiri/nokogiri.jar +0 -0
  51. data/lib/nokogiri/version/constant.rb +1 -1
  52. data/lib/nokogiri/xml/attribute_decl.rb +4 -2
  53. data/lib/nokogiri/xml/document_fragment.rb +1 -1
  54. data/lib/nokogiri/xml/element_content.rb +10 -2
  55. data/lib/nokogiri/xml/element_decl.rb +4 -2
  56. data/lib/nokogiri/xml/entity_decl.rb +4 -2
  57. data/lib/nokogiri/xml/node/save_options.rb +8 -0
  58. data/lib/nokogiri/xml/node.rb +22 -13
  59. data/lib/nokogiri/xml/pp/node.rb +23 -12
  60. data/lib/nokogiri/xml/sax/document.rb +1 -1
  61. data/lib/nokogiri/xml/searchable.rb +18 -10
  62. data/lib/nokogiri/xslt.rb +73 -3
  63. data/lib/nokogiri.rb +12 -4
  64. data/lib/xsd/xmlparser/nokogiri.rb +1 -1
  65. metadata +4 -4
  66. data/lib/nokogiri/jruby/org/nokogiri/nekodtd/0.1.11.noko2/nekodtd-0.1.11.noko2.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 290237d5f10953257ff144b99f10352dbe522310c139d1675346af05870fda87
4
- data.tar.gz: d2ca4a5b533de262f308a945f76e8a437cebe84670698921a330adb88a43bc23
3
+ metadata.gz: 77aa99dfd4573719740455b1274f17b9dfedf73064975fd059de9a770f0cc32c
4
+ data.tar.gz: 8813970061dfecd1c218d8f0267e64f383ef5fce6ef5a8c23e7c4d91d173a0b2
5
5
  SHA512:
6
- metadata.gz: 310d6267a0fc497095c2629ddd516bdf6cb8d192a6bfcd11470a281b75f3d66ba8a4edd8a40eaf203cb0b53e0f33db12a4191641be3318049b7738af79a0d7af
7
- data.tar.gz: 7a383b7e0a0c2da84d83984bbebb0e5c056bd9bfe669f9ba99c269294f86c274fd97c3f2e5a71e77b66bbaf67c067514dcf528db76c0ea78deaac11a0048377e
6
+ metadata.gz: bac6f68aac57e8c3e47d1ccdb4db199815236ec34e6e7f425a804d973a642572944c34e0afb9caf78cdec707b8ff919fbd6414ddee519d75c43890256231f30d
7
+ data.tar.gz: 24d44e5487c4cd00dcb65947eb1b6aa50932cdc87b79daa60a9c9811ea3f48a6e27965f01277686760ad327f78d0112e3f8de798fb4712c3e2fec85bd490472e
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"
@@ -227,7 +227,6 @@ public class NokogiriService implements BasicLibraryService
227
227
  {
228
228
  RubyClass stylesheet = xsltModule.defineClassUnder("Stylesheet", ruby.getObject(), XSLT_STYLESHEET_ALLOCATOR);
229
229
  stylesheet.defineAnnotatedMethods(XsltStylesheet.class);
230
- xsltModule.defineAnnotatedMethod(XsltStylesheet.class, "register");
231
230
  }
232
231
 
233
232
  public static final ObjectAllocator HTML_DOCUMENT_ALLOCATOR = new ObjectAllocator()
@@ -45,6 +45,12 @@ public class XmlCdata extends XmlText
45
45
  }
46
46
  IRubyObject doc = args[0];
47
47
  content = args[1];
48
+
49
+ if (!(doc instanceof XmlDocument)) {
50
+ // TODO: deprecate allowing Node
51
+ context.runtime.getWarnings().warn("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.");
52
+ }
53
+
48
54
  Document document = ((XmlNode) doc).getOwnerDocument();
49
55
  Node node = document.createCDATASection(rubyStringToString(content));
50
56
  setNode(context.runtime, node);
@@ -762,14 +762,14 @@ public class XmlNode extends RubyObject
762
762
  if (children.getLength() == 0) {
763
763
  return Collections.emptyList();
764
764
  }
765
- ArrayList<Node> elements = firstOnly ? null : new ArrayList<Node>(children.getLength());
765
+ ArrayList<Node> elements = new ArrayList<Node>();
766
766
  for (int i = 0; i < children.getLength(); i++) {
767
767
  Node child = children.item(i);
768
768
  if (child.getNodeType() == Node.ELEMENT_NODE) {
769
+ elements.add(child);
769
770
  if (firstOnly) {
770
- return Collections.singletonList(child);
771
+ return elements;
771
772
  }
772
- elements.add(child);
773
773
  }
774
774
  }
775
775
  return elements;
@@ -1342,12 +1342,21 @@ public class XmlNode extends RubyObject
1342
1342
  IRubyObject io = args[0];
1343
1343
  IRubyObject encoding = args[1];
1344
1344
  IRubyObject indentString = args[2];
1345
- IRubyObject options = args[3];
1345
+ IRubyObject options_rb = args[3];
1346
+ int options = RubyFixnum.fix2int(options_rb);
1346
1347
 
1347
1348
  String encString = rubyStringToString(encoding);
1348
1349
 
1350
+ // similar to behavior of libxml2's xmlSaveTree function
1351
+ if ((options & SaveContextVisitor.AS_XML) == 0 &&
1352
+ (options & SaveContextVisitor.AS_XHTML) == 0 &&
1353
+ (options & SaveContextVisitor.AS_HTML) == 0 &&
1354
+ isHtmlDoc(context)) {
1355
+ options |= SaveContextVisitor.DEFAULT_HTML;
1356
+ }
1357
+
1349
1358
  SaveContextVisitor visitor =
1350
- new SaveContextVisitor(RubyFixnum.fix2int(options), rubyStringToString(indentString), encString, isHtmlDoc(context),
1359
+ new SaveContextVisitor(options, rubyStringToString(indentString), encString, isHtmlDoc(context),
1351
1360
  isFragment(), 0);
1352
1361
  accept(context, visitor);
1353
1362
 
@@ -149,6 +149,11 @@ public class XmlSchema extends RubyObject
149
149
  parseOptions = args[1];
150
150
  }
151
151
 
152
+ if (!(document instanceof XmlDocument)) {
153
+ // TODO: deprecate allowing Node
154
+ context.runtime.getWarnings().warn("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
155
+ }
156
+
152
157
  XmlDocument doc = ((XmlDocument)((XmlNode) document).document(context));
153
158
 
154
159
  RubyArray<?> errors = (RubyArray) doc.getInstanceVariable("@errors");
@@ -53,6 +53,11 @@ public class XmlText extends XmlNode
53
53
  content = args[0];
54
54
  IRubyObject xNode = args[1];
55
55
 
56
+ if (!(xNode instanceof XmlDocument)) {
57
+ // TODO: deprecate allowing Node
58
+ context.runtime.getWarnings().warn("Passing a Node as the second parameter to Text.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
59
+ }
60
+
56
61
  Document document = asXmlNode(context, xNode).getOwnerDocument();
57
62
  // text node content should not be encoded when it is created by Text node.
58
63
  // while content should be encoded when it is created by Element node.
@@ -80,14 +80,12 @@ public class XsltStylesheet extends RubyObject
80
80
  private void
81
81
  addParametersToTransformer(ThreadContext context, Transformer transf, IRubyObject parameters)
82
82
  {
83
- Ruby runtime = context.getRuntime();
84
-
85
83
  if (parameters instanceof RubyHash) {
86
84
  setHashParameters(transf, (RubyHash)parameters);
87
85
  } else if (parameters instanceof RubyArray) {
88
- setArrayParameters(transf, runtime, (RubyArray)parameters);
86
+ setArrayParameters(transf, context, (RubyArray)parameters);
89
87
  } else {
90
- throw runtime.newTypeError("parameters should be given either Array or Hash");
88
+ throw context.getRuntime().newTypeError("parameters should be given either Array or Hash");
91
89
  }
92
90
  }
93
91
 
@@ -101,14 +99,14 @@ public class XsltStylesheet extends RubyObject
101
99
  }
102
100
 
103
101
  private void
104
- setArrayParameters(Transformer transformer, Ruby runtime, RubyArray<?> params)
102
+ setArrayParameters(Transformer transformer, ThreadContext context, RubyArray<?> params)
105
103
  {
106
104
  int limit = params.getLength();
107
105
  if (limit % 2 == 1) { limit--; }
108
106
 
109
107
  for (int i = 0; i < limit; i += 2) {
110
- String name = params.aref(runtime.newFixnum(i)).asJavaString();
111
- String value = params.aref(runtime.newFixnum(i + 1)).asJavaString();
108
+ String name = params.aref(context, context.getRuntime().newFixnum(i)).asJavaString();
109
+ String value = params.aref(context, context.getRuntime().newFixnum(i + 1)).asJavaString();
112
110
  transformer.setParameter(name, unparseValue(value));
113
111
  }
114
112
  }
@@ -352,17 +350,4 @@ public class XsltStylesheet extends RubyObject
352
350
  if (arg instanceof XmlDocument) { return; }
353
351
  throw runtime.newArgumentError("argument must be a Nokogiri::XML::Document");
354
352
  }
355
-
356
- @JRubyMethod(name = {"registr", "register"}, meta = true)
357
- public static IRubyObject
358
- register(ThreadContext context, IRubyObject cls, IRubyObject uri, IRubyObject receiver)
359
- {
360
- throw context.getRuntime().newNotImplementedError("Nokogiri::XSLT.register method is not implemented");
361
- /* When API conflict is solved, this method should be below:
362
- // ThreadContext is used while executing xslt extension function
363
- registry.put("context", context);
364
- registry.put("receiver", receiver);
365
- return context.getRuntime().getNil();
366
- */
367
- }
368
353
  }
@@ -56,9 +56,7 @@ public class HtmlDomParserContext extends XmlDomParserContext
56
56
  initParser(Ruby runtime)
57
57
  {
58
58
  XMLParserConfiguration config = new HTMLConfiguration();
59
- //XMLDocumentFilter removeNSAttrsFilter = new RemoveNSAttrsFilter();
60
59
  XMLDocumentFilter elementValidityCheckFilter = new ElementValidityCheckFilter(errorHandler);
61
- //XMLDocumentFilter[] filters = { removeNSAttrsFilter, elementValidityCheckFilter};
62
60
  XMLDocumentFilter[] filters = { elementValidityCheckFilter};
63
61
 
64
62
  config.setErrorHandler(this.errorHandler);
@@ -162,29 +160,6 @@ public class HtmlDomParserContext extends XmlDomParserContext
162
160
  return null;
163
161
  }
164
162
 
165
- /**
166
- * Filter to strip out attributes that pertain to XML namespaces.
167
- */
168
- public static class RemoveNSAttrsFilter extends DefaultFilter
169
- {
170
- @Override
171
- public void
172
- startElement(QName element, XMLAttributes attrs,
173
- Augmentations augs) throws XNIException
174
- {
175
- int i;
176
- for (i = 0; i < attrs.getLength(); ++i) {
177
- if (isNamespace(attrs.getQName(i))) {
178
- attrs.removeAttributeAt(i);
179
- --i;
180
- }
181
- }
182
-
183
- element.uri = null;
184
- super.startElement(element, attrs, augs);
185
- }
186
- }
187
-
188
163
  public static class ElementValidityCheckFilter extends DefaultFilter
189
164
  {
190
165
  private NokogiriErrorHandler errorHandler;
@@ -74,6 +74,7 @@ public class SaveContextVisitor
74
74
  public static final int AS_XML = 32;
75
75
  public static final int AS_HTML = 64;
76
76
  public static final int AS_BUILDER = 128;
77
+ public static final int DEFAULT_HTML = NO_DECL | NO_EMPTY | AS_HTML;
77
78
 
78
79
  public static final int CANONICAL = 1;
79
80
  public static final int INCL_NS = 2;
@@ -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