nokogiri 1.17.2-x86_64-darwin → 1.18.0.rc1-x86_64-darwin

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d38ca50cb49ca6223d6c159df795e87b03b04a70589d68cf38bb61f6d507f968
4
- data.tar.gz: 178ea01f9cd43b77428f187d0e569b6bb4b3a2b12915f647c800f5b796c77e83
3
+ metadata.gz: 1008eb31cbcdd2bf397f5395107f433da8699571fc15ca1a35db03abce125e6f
4
+ data.tar.gz: adf57cf0667a4f60008e9347783c5bb38a6dc5f70c36468073a1a714f3dab46d
5
5
  SHA512:
6
- metadata.gz: 1c07642dcf956e39c3a2c9aed85e09224afd1d1d884183e1297f7658c226e95c058fefc5d998ba51935d2b00029f489c02d23d7de9f37794e46391510a44fd5d
7
- data.tar.gz: 50d246e076d29fb6882344d9c8455a37081790d862c1b708a0a0ec38849e4add37f2d9d633b3328d158eb9981fadd1e92ad4081fed4c009f504bc24e8cb2f3d6
6
+ metadata.gz: 9b42628e060b3b7e1871eeca860a4a635067bc90856f4ded62aff82cc200ede9665723760233b8792b03cfee3c6363dd056f446e88a7630ea966f9c0f0ae13dd
7
+ data.tar.gz: 0f071ef4dc1f9a4a47ce3de35b3991150e78aba864064b8f0360b0046dfb8232c24fe325bcf9178fa96ec5ec5c911102f10946b0e05c0bcb8e34063b05af9db9
data/Gemfile CHANGED
@@ -11,20 +11,20 @@ group :development do
11
11
 
12
12
  # building extensions
13
13
  gem "rake-compiler", "1.2.8"
14
- gem "rake-compiler-dock", "1.5.2"
14
+ gem "rake-compiler-dock", "1.7.0.rc1"
15
15
 
16
16
  # parser generator
17
17
  gem "rexical", "1.0.8"
18
18
 
19
19
  # tests
20
- gem "minitest", "5.25.2"
20
+ gem "minitest", "5.25.4"
21
21
  gem "minitest-parallel_fork", "2.0.0"
22
22
  gem "ruby_memcheck", "3.0.0"
23
23
  gem "rubyzip", "~> 2.3.2"
24
24
  gem "simplecov", "= 0.21.2"
25
25
 
26
26
  # rubocop
27
- gem "standard", "1.42.1"
27
+ gem "standard", "1.43.0"
28
28
  gem "rubocop-minitest", "0.36.0"
29
29
  gem "rubocop-packaging", "0.5.2"
30
30
  gem "rubocop-rake", "0.6.0"
@@ -34,5 +34,5 @@ end
34
34
  # `bundle config set --local without rdoc`
35
35
  # Then re-run `bundle install`.
36
36
  group :rdoc do
37
- gem "rdoc", "6.8.1"
37
+ gem "rdoc", "6.9.0"
38
38
  end
@@ -10,9 +10,9 @@ Note that this document is broken into multiple sections, each of which describe
10
10
 
11
11
  - [Platform Releases](#platform-releases)
12
12
  * [Default platform release ("ruby")](#default-platform-release-ruby)
13
- * [Native LinuxⓇ platform releases ("x86_64-linux", "arm64-linux", "aarch64-linux", and "arm-linux")](#native-linux%E2%93%A1-platform-releases-x86_64-linux-arm64-linux-aarch64-linux-and-arm-linux)
13
+ * [Native LinuxⓇ platform releases ("x86_64-linux", "aarch64-linux", and "arm-linux")](#native-linux%E2%93%A1-platform-releases-x86_64-linux-aarch64-linux-and-arm-linux)
14
14
  * [Native Darwin (macOSⓇ) platform releases ("x86_64-darwin" and "arm64-darwin")](#native-darwin-macos%E2%93%A1-platform-releases-x86_64-darwin-and-arm64-darwin)
15
- * [Native WindowsⓇ platform releases ("x86-mingw32" and "x64-mingw32")](#native-windows%E2%93%A1-platform-releases-x86-mingw32-and-x64-mingw32)
15
+ * [Native WindowsⓇ platform releases ("x64-mingw-ucrt")](#native-windows%E2%93%A1-platform-releases-x64-mingw-ucrt)
16
16
  * [JavaⓇ (JRuby) platform release ("java")](#java%E2%93%A1-jruby-platform-release-java)
17
17
  - [Appendix: Dependencies' License Texts](#appendix-dependencies-license-texts)
18
18
  * [libgumbo](#libgumbo)
@@ -51,7 +51,7 @@ The default platform release distributes the following dependencies in source fo
51
51
  This distribution can be identified by inspecting the included Gem::Specification, which will have the value "ruby" for its "platform" attribute.
52
52
 
53
53
 
54
- ### Native LinuxⓇ platform releases ("x86_64-linux", "arm64-linux", "aarch64-linux", and "arm-linux")
54
+ ### Native LinuxⓇ platform releases ("x86_64-linux", "aarch64-linux", and "arm-linux")
55
55
 
56
56
  The native LinuxⓇ platform release distributes the following dependencies in source form:
57
57
 
@@ -60,7 +60,7 @@ The native LinuxⓇ platform release distributes the following dependencies in s
60
60
  * [libgumbo](#libgumbo)
61
61
  * [zlib](#zlib)
62
62
 
63
- This distribution can be identified by inspecting the included Gem::Specification, which will have a value similar to "x86_64-linux" or "arm64-linux" for its "platform.cpu" attribute.
63
+ This distribution can be identified by inspecting the included Gem::Specification, which will have a value similar to "x86_64-linux" or "aarch64-linux" for its "platform.cpu" attribute.
64
64
 
65
65
 
66
66
  ### Native Darwin (macOSⓇ) platform releases ("x86_64-darwin" and "arm64-darwin")
@@ -76,7 +76,7 @@ The native Darwin platform release distributes the following dependencies in sou
76
76
  This distribution can be identified by inspecting the included Gem::Specification, which will have a value similar to "x86_64-darwin" or "arm64-darwin" for its "platform.cpu" attribute. Darwin is also known more familiarly as "OSX" or "macOSⓇ" and is the operating system for many AppleⓇ computers.
77
77
 
78
78
 
79
- ### Native WindowsⓇ platform releases ("x86-mingw32" and "x64-mingw32")
79
+ ### Native WindowsⓇ platform releases ("x64-mingw-ucrt")
80
80
 
81
81
  The native WindowsⓇ platform release distributes the following dependencies in source form:
82
82
 
@@ -86,7 +86,7 @@ The native WindowsⓇ platform release distributes the following dependencies in
86
86
  * [zlib](#zlib)
87
87
  * [libiconv](#libiconv)
88
88
 
89
- This distribution can be identified by inspecting the included Gem::Specification, which will have a value similar to "x64-mingw32" or "x86-mingw32" for its "platform.cpu" attribute.
89
+ This distribution can be identified by inspecting the included Gem::Specification, which will have a value similar to "x64-mingw-ucrt" for its "platform.cpu" attribute.
90
90
 
91
91
 
92
92
  ### JavaⓇ (JRuby) platform release ("java")
data/README.md CHANGED
@@ -114,7 +114,7 @@ You can help sponsor the maintainers of this software through one of these organ
114
114
 
115
115
  Requirements:
116
116
 
117
- - Ruby >= 3.0
117
+ - Ruby >= 3.1
118
118
  - JRuby >= 9.4.0.0
119
119
 
120
120
  If you are compiling the native extension against a system version of libxml2:
@@ -131,11 +131,10 @@ If you are compiling the native extension against a system version of libxml2:
131
131
  Nokogiri ships pre-compiled, "native" gems for the following platforms:
132
132
 
133
133
  - Linux:
134
- - `x86-linux` and `x86_64-linux` (req: `glibc >= 2.17`)
135
- - `aarch64-linux` and `arm-linux` (req: `glibc >= 2.29`)
136
- - Note that musl platforms like Alpine **are** supported
134
+ - `x86_64-linux-gnu`, `aarch64-linux-gnu`, and `arm-linux-gnu` (req: `glibc >= 2.29`)
135
+ - `x86_64-linux-musl`, `aarch64-linux-musl`, and `arm-linux-musl`
137
136
  - Darwin/MacOS: `x86_64-darwin` and `arm64-darwin`
138
- - Windows: `x86-mingw32`, `x64-mingw32`, and `x64-mingw-ucrt`
137
+ - Windows: `x64-mingw-ucrt`
139
138
  - Java: any platform running JRuby 9.4 or higher
140
139
 
141
140
  To determine whether your system supports one of these gems, look at the output of `bundle platform` or `ruby -e 'puts Gem::Platform.local.to_s'`.
@@ -847,7 +847,7 @@ else
847
847
  # The libiconv configure script doesn't accept "arm64" host string but "aarch64"
848
848
  recipe.host = recipe.host.gsub("arm64-apple-darwin", "aarch64-apple-darwin")
849
849
 
850
- cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
850
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-g")
851
851
 
852
852
  recipe.configure_options += [
853
853
  "--disable-dependency-tracking",
@@ -911,7 +911,7 @@ else
911
911
  end
912
912
 
913
913
  cppflags = concat_flags(ENV["CPPFLAGS"])
914
- cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
914
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-g")
915
915
 
916
916
  if cross_build_p
917
917
  cppflags = concat_flags(cppflags, "-DNOKOGIRI_PRECOMPILED_LIBRARIES")
@@ -952,7 +952,6 @@ else
952
952
  "--with-c14n",
953
953
  "--with-debug",
954
954
  "--with-threads",
955
- "--without-tls", # see https://github.com/sparklemotion/nokogiri/issues/3031
956
955
  "CPPFLAGS=#{cppflags}",
957
956
  "CFLAGS=#{cflags}",
958
957
  ]
@@ -971,7 +970,7 @@ else
971
970
  recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", "libxslt", "*.patch")].sort
972
971
  end
973
972
 
974
- cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
973
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-g")
975
974
 
976
975
  if darwin? && !cross_build_p
977
976
  recipe.configure_options << "RANLIB=/usr/bin/ranlib" unless ENV.key?("RANLIB")
@@ -1117,14 +1116,7 @@ else
1117
1116
  end
1118
1117
  env["RANLIB"] = "#{host}-ranlib"
1119
1118
  if windows?
1120
- # NOTE: that in any particular windows gem package, we only ever compile against either
1121
- # msvcrt (ruby <= 3.0) or ucrt (ruby > 3.0), so even though this gets evaluated only once
1122
- # per gem (and not per-version-of-ruby), it's OK.
1123
- env["CFLAGS"] = if RbConfig::CONFIG["RUBY_SO_NAME"].include?("msvcrt")
1124
- concat_flags(env["CFLAGS"], "-D_RUBY_MSVCRT")
1125
- else
1126
- concat_flags(env["CFLAGS"], "-D_RUBY_UCRT")
1127
- end
1119
+ concat_flags(env["CFLAGS"], "-D_RUBY_UCRT")
1128
1120
  end
1129
1121
  end
1130
1122
 
@@ -1141,7 +1133,7 @@ end
1141
1133
  have_func("xmlCtxtSetOptions") # introduced in libxml2 2.13.0
1142
1134
  have_func("xmlCtxtGetOptions") # introduced in libxml2 2.14.0
1143
1135
  have_func("xmlSwitchEncodingName") # introduced in libxml2 2.13.0
1144
- have_func("rb_category_warning") # introduced in Ruby 3.0
1136
+ have_func("rb_category_warning") # introduced in Ruby 3.0 but had trouble resolving this symbol in truffleruby
1145
1137
 
1146
1138
  other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k, v| [k, v].join(":") }.join(",")
1147
1139
  append_cppflags(%[-DNOKOGIRI_OTHER_LIBRARY_VERSIONS="\\"#{other_library_versions_string}\\""])
@@ -12,23 +12,23 @@ static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-built
12
12
  static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
13
13
 
14
14
  static void
15
- xml_xpath_context_deallocate(void *data)
15
+ _noko_xml_xpath_context_dfree(void *data)
16
16
  {
17
17
  xmlXPathContextPtr c_context = data;
18
18
  xmlXPathFreeContext(c_context);
19
19
  }
20
20
 
21
- static const rb_data_type_t xml_xpath_context_type = {
21
+ static const rb_data_type_t _noko_xml_xpath_context_type = {
22
22
  .wrap_struct_name = "xmlXPathContext",
23
23
  .function = {
24
- .dfree = xml_xpath_context_deallocate,
24
+ .dfree = _noko_xml_xpath_context_dfree,
25
25
  },
26
26
  .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
27
27
  };
28
28
 
29
29
  /* find a CSS class in an HTML element's `class` attribute */
30
30
  static const xmlChar *
31
- builtin_css_class(const xmlChar *str, const xmlChar *val)
31
+ _noko_xml_xpath_context__css_class(const xmlChar *str, const xmlChar *val)
32
32
  {
33
33
  int val_len;
34
34
 
@@ -62,9 +62,9 @@ builtin_css_class(const xmlChar *str, const xmlChar *val)
62
62
  return (NULL);
63
63
  }
64
64
 
65
- /* xmlXPathFunction to wrap builtin_css_class() */
65
+ /* xmlXPathFunction to wrap _noko_xml_xpath_context__css_class() */
66
66
  static void
67
- xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
67
+ noko_xml_xpath_context_xpath_func_css_class(xmlXPathParserContextPtr ctxt, int nargs)
68
68
  {
69
69
  xmlXPathObjectPtr hay, needle;
70
70
 
@@ -85,7 +85,7 @@ xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
85
85
  XP_ERROR(XPATH_INVALID_TYPE);
86
86
  }
87
87
 
88
- if (builtin_css_class(hay->stringval, needle->stringval)) {
88
+ if (_noko_xml_xpath_context__css_class(hay->stringval, needle->stringval)) {
89
89
  valuePush(ctxt, xmlXPathNewBoolean(1));
90
90
  } else {
91
91
  valuePush(ctxt, xmlXPathNewBoolean(0));
@@ -99,7 +99,7 @@ xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
99
99
  /* xmlXPathFunction to select nodes whose local name matches, for HTML5 CSS queries that should
100
100
  * ignore namespaces */
101
101
  static void
102
- xpath_builtin_local_name_is(xmlXPathParserContextPtr ctxt, int nargs)
102
+ noko_xml_xpath_context_xpath_func_local_name_is(xmlXPathParserContextPtr ctxt, int nargs)
103
103
  {
104
104
  xmlXPathObjectPtr element_name;
105
105
 
@@ -124,25 +124,33 @@ xpath_builtin_local_name_is(xmlXPathParserContextPtr ctxt, int nargs)
124
124
  * register_ns(prefix, uri) → Nokogiri::XML::XPathContext
125
125
  *
126
126
  * Register the namespace with +prefix+ and +uri+ for use in future queries.
127
+ * Passing a uri of +nil+ will unregister the namespace.
127
128
  *
128
129
  * [Returns] +self+
129
130
  */
130
131
  static VALUE
131
- rb_xml_xpath_context_register_ns(VALUE rb_context, VALUE prefix, VALUE uri)
132
+ noko_xml_xpath_context_register_ns(VALUE rb_context, VALUE prefix, VALUE uri)
132
133
  {
133
134
  xmlXPathContextPtr c_context;
135
+ const xmlChar *ns_uri;
134
136
 
135
- TypedData_Get_Struct(
136
- rb_context,
137
- xmlXPathContext,
138
- &xml_xpath_context_type,
139
- c_context
140
- );
137
+ TypedData_Get_Struct(rb_context, xmlXPathContext, &_noko_xml_xpath_context_type, c_context);
138
+
139
+ if (NIL_P(uri)) {
140
+ ns_uri = NULL;
141
+ } else {
142
+ ns_uri = (const xmlChar *)StringValueCStr(uri);
143
+ }
144
+
145
+ xmlXPathRegisterNs(c_context, (const xmlChar *)StringValueCStr(prefix), ns_uri);
146
+
147
+ VALUE registered_namespaces = rb_iv_get(rb_context, "@registered_namespaces");
148
+ if (NIL_P(uri)) {
149
+ rb_hash_delete(registered_namespaces, prefix);
150
+ } else {
151
+ rb_hash_aset(registered_namespaces, prefix, Qtrue);
152
+ }
141
153
 
142
- xmlXPathRegisterNs(c_context,
143
- (const xmlChar *)StringValueCStr(prefix),
144
- (const xmlChar *)StringValueCStr(uri)
145
- );
146
154
  return rb_context;
147
155
  }
148
156
 
@@ -151,29 +159,32 @@ rb_xml_xpath_context_register_ns(VALUE rb_context, VALUE prefix, VALUE uri)
151
159
  * register_variable(name, value) → Nokogiri::XML::XPathContext
152
160
  *
153
161
  * Register the variable +name+ with +value+ for use in future queries.
162
+ * Passing a value of +nil+ will unregister the variable.
154
163
  *
155
164
  * [Returns] +self+
156
165
  */
157
166
  static VALUE
158
- rb_xml_xpath_context_register_variable(VALUE rb_context, VALUE name, VALUE value)
167
+ noko_xml_xpath_context_register_variable(VALUE rb_context, VALUE name, VALUE value)
159
168
  {
160
169
  xmlXPathContextPtr c_context;
161
170
  xmlXPathObjectPtr xmlValue;
162
171
 
163
- TypedData_Get_Struct(
164
- rb_context,
165
- xmlXPathContext,
166
- &xml_xpath_context_type,
167
- c_context
168
- );
172
+ TypedData_Get_Struct(rb_context, xmlXPathContext, &_noko_xml_xpath_context_type, c_context);
169
173
 
170
- xmlValue = xmlXPathNewCString(StringValueCStr(value));
174
+ if (NIL_P(value)) {
175
+ xmlValue = NULL;
176
+ } else {
177
+ xmlValue = xmlXPathNewCString(StringValueCStr(value));
178
+ }
171
179
 
172
- xmlXPathRegisterVariable(
173
- c_context,
174
- (const xmlChar *)StringValueCStr(name),
175
- xmlValue
176
- );
180
+ xmlXPathRegisterVariable(c_context, (const xmlChar *)StringValueCStr(name), xmlValue);
181
+
182
+ VALUE registered_variables = rb_iv_get(rb_context, "@registered_variables");
183
+ if (NIL_P(value)) {
184
+ rb_hash_delete(registered_variables, name);
185
+ } else {
186
+ rb_hash_aset(registered_variables, name, Qtrue);
187
+ }
177
188
 
178
189
  return rb_context;
179
190
  }
@@ -184,7 +195,7 @@ rb_xml_xpath_context_register_variable(VALUE rb_context, VALUE name, VALUE value
184
195
  * returns Qundef if no conversion was possible.
185
196
  */
186
197
  static VALUE
187
- xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr c_context)
198
+ _noko_xml_xpath_context__xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr c_context)
188
199
  {
189
200
  VALUE rb_retval;
190
201
 
@@ -238,7 +249,7 @@ Nokogiri_marshal_xpath_funcall_and_return_values(
238
249
 
239
250
  for (int j = argc - 1 ; j >= 0 ; --j) {
240
251
  c_xpath_object = valuePop(ctxt);
241
- argv[j] = xpath2ruby(c_xpath_object, ctxt->context);
252
+ argv[j] = _noko_xml_xpath_context__xpath2ruby(c_xpath_object, ctxt->context);
242
253
  if (argv[j] == Qundef) {
243
254
  argv[j] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(c_xpath_object));
244
255
  }
@@ -294,7 +305,7 @@ Nokogiri_marshal_xpath_funcall_and_return_values(
294
305
  }
295
306
 
296
307
  static void
297
- method_caller(xmlXPathParserContextPtr ctxt, int argc)
308
+ _noko_xml_xpath_context__handler_invoker(xmlXPathParserContextPtr ctxt, int argc)
298
309
  {
299
310
  VALUE rb_xpath_handler = Qnil;
300
311
  const char *method_name = NULL ;
@@ -316,15 +327,15 @@ method_caller(xmlXPathParserContextPtr ctxt, int argc)
316
327
  }
317
328
 
318
329
  static xmlXPathFunction
319
- handler_lookup(void *data, const xmlChar *c_name, const xmlChar *c_ns_uri)
330
+ _noko_xml_xpath_context_handler_lookup(void *data, const xmlChar *c_name, const xmlChar *c_ns_uri)
320
331
  {
321
332
  VALUE rb_handler = (VALUE)data;
322
333
  if (rb_respond_to(rb_handler, rb_intern((const char *)c_name))) {
323
334
  if (c_ns_uri == NULL) {
324
335
  NOKO_WARN_DEPRECATION("A custom XPath or CSS handler function named '%s' is being invoked without a namespace. Please update your query to reference this function as 'nokogiri:%s'. Invoking custom handler functions without a namespace is deprecated and will become an error in Nokogiri v1.17.0.",
325
- c_name, c_name); // deprecated in v1.15.0, remove in v1.17.0
336
+ c_name, c_name); // TODO deprecated in v1.15.0, remove in v1.19.0
326
337
  }
327
- return method_caller;
338
+ return _noko_xml_xpath_context__handler_invoker;
328
339
  }
329
340
 
330
341
  return NULL;
@@ -332,7 +343,7 @@ handler_lookup(void *data, const xmlChar *c_name, const xmlChar *c_ns_uri)
332
343
 
333
344
  PRINTFLIKE_DECL(2, 3)
334
345
  static void
335
- generic_exception_pusher(void *data, const char *msg, ...)
346
+ _noko_xml_xpath_context__generic_exception_pusher(void *data, const char *msg, ...)
336
347
  {
337
348
  VALUE rb_errors = (VALUE)data;
338
349
  VALUE rb_message;
@@ -343,7 +354,7 @@ generic_exception_pusher(void *data, const char *msg, ...)
343
354
  #ifdef TRUFFLERUBY_NOKOGIRI_SYSTEM_LIBRARIES
344
355
  /* It is not currently possible to pass var args from native
345
356
  functions to sulong, so we work around the issue here. */
346
- rb_message = rb_sprintf("generic_exception_pusher: %s", msg);
357
+ rb_message = rb_sprintf("_noko_xml_xpath_context__generic_exception_pusher: %s", msg);
347
358
  #else
348
359
  va_list args;
349
360
  va_start(args, msg);
@@ -365,58 +376,54 @@ generic_exception_pusher(void *data, const char *msg, ...)
365
376
  * a +Float+, or a boolean.
366
377
  */
367
378
  static VALUE
368
- rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE rb_context)
379
+ noko_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE rb_context)
369
380
  {
370
- VALUE search_path, xpath_handler;
371
- VALUE retval = Qnil;
372
381
  xmlXPathContextPtr c_context;
373
- xmlXPathObjectPtr xpath;
374
- xmlChar *query;
375
- VALUE errors = rb_ary_new();
376
-
377
- TypedData_Get_Struct(
378
- rb_context,
379
- xmlXPathContext,
380
- &xml_xpath_context_type,
381
- c_context
382
- );
382
+ VALUE rb_expression = Qnil;
383
+ VALUE rb_function_lookup_handler = Qnil;
384
+ xmlChar *c_expression_str = NULL;
385
+ VALUE rb_errors = rb_ary_new();
386
+ xmlXPathObjectPtr c_xpath_object;
387
+ VALUE rb_xpath_object = Qnil;
383
388
 
384
- if (rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1) {
385
- xpath_handler = Qnil;
386
- }
389
+ TypedData_Get_Struct(rb_context, xmlXPathContext, &_noko_xml_xpath_context_type, c_context);
390
+
391
+ rb_scan_args(argc, argv, "11", &rb_expression, &rb_function_lookup_handler);
387
392
 
388
- query = (xmlChar *)StringValueCStr(search_path);
393
+ c_expression_str = (xmlChar *)StringValueCStr(rb_expression);
389
394
 
390
- if (Qnil != xpath_handler) {
395
+ if (Qnil != rb_function_lookup_handler) {
391
396
  /* FIXME: not sure if this is the correct place to shove private data. */
392
- c_context->userData = (void *)xpath_handler;
397
+ c_context->userData = (void *)rb_function_lookup_handler;
393
398
  xmlXPathRegisterFuncLookup(
394
399
  c_context,
395
- handler_lookup,
396
- (void *)xpath_handler
400
+ _noko_xml_xpath_context_handler_lookup,
401
+ (void *)rb_function_lookup_handler
397
402
  );
398
403
  }
399
404
 
400
- xmlSetStructuredErrorFunc((void *)errors, noko__error_array_pusher);
401
- xmlSetGenericErrorFunc((void *)errors, generic_exception_pusher);
405
+ xmlSetStructuredErrorFunc((void *)rb_errors, noko__error_array_pusher);
406
+ xmlSetGenericErrorFunc((void *)rb_errors, _noko_xml_xpath_context__generic_exception_pusher);
402
407
 
403
- xpath = xmlXPathEvalExpression(query, c_context);
408
+ c_xpath_object = xmlXPathEvalExpression(c_expression_str, c_context);
404
409
 
405
410
  xmlSetStructuredErrorFunc(NULL, NULL);
406
411
  xmlSetGenericErrorFunc(NULL, NULL);
407
412
 
408
- if (xpath == NULL) {
409
- rb_exc_raise(rb_ary_entry(errors, 0));
413
+ xmlXPathRegisterFuncLookup(c_context, NULL, NULL);
414
+
415
+ if (c_xpath_object == NULL) {
416
+ rb_exc_raise(rb_ary_entry(rb_errors, 0));
410
417
  }
411
418
 
412
- retval = xpath2ruby(xpath, c_context);
413
- if (retval == Qundef) {
414
- retval = noko_xml_node_set_wrap(NULL, DOC_RUBY_OBJECT(c_context->doc));
419
+ rb_xpath_object = _noko_xml_xpath_context__xpath2ruby(c_xpath_object, c_context);
420
+ if (rb_xpath_object == Qundef) {
421
+ rb_xpath_object = noko_xml_node_set_wrap(NULL, DOC_RUBY_OBJECT(c_context->doc));
415
422
  }
416
423
 
417
- xmlXPathFreeNodeSetList(xpath);
424
+ xmlXPathFreeNodeSetList(c_xpath_object);
418
425
 
419
- return retval;
426
+ return rb_xpath_object;
420
427
  }
421
428
 
422
429
  /*
@@ -426,45 +433,56 @@ rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE rb_context)
426
433
  * Create a new XPathContext with +node+ as the context node.
427
434
  */
428
435
  static VALUE
429
- rb_xml_xpath_context_new(VALUE klass, VALUE rb_node)
436
+ noko_xml_xpath_context_new(VALUE klass, VALUE rb_node)
430
437
  {
431
- xmlNodePtr node;
438
+ xmlNodePtr c_node;
432
439
  xmlXPathContextPtr c_context;
433
440
  VALUE rb_context;
434
441
 
435
- Noko_Node_Get_Struct(rb_node, xmlNode, node);
442
+ Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
436
443
 
437
444
  #if LIBXML_VERSION < 21000
438
- /* deprecated in 40483d0 */
439
- xmlXPathInit();
445
+ xmlXPathInit(); /* deprecated in 40483d0 */
440
446
  #endif
441
447
 
442
- c_context = xmlXPathNewContext(node->doc);
443
- c_context->node = node;
448
+ c_context = xmlXPathNewContext(c_node->doc);
449
+ c_context->node = c_node;
444
450
 
445
451
  xmlXPathRegisterNs(c_context, NOKOGIRI_PREFIX, NOKOGIRI_URI);
446
452
  xmlXPathRegisterNs(c_context, NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
447
- xmlXPathRegisterFuncNS(
448
- c_context,
449
- (const xmlChar *)"css-class",
450
- NOKOGIRI_BUILTIN_URI,
451
- xpath_builtin_css_class
452
- );
453
- xmlXPathRegisterFuncNS(
454
- c_context,
455
- (const xmlChar *)"local-name-is",
456
- NOKOGIRI_BUILTIN_URI,
457
- xpath_builtin_local_name_is
458
- );
459
453
 
460
- rb_context = TypedData_Wrap_Struct(
461
- klass,
462
- &xml_xpath_context_type,
463
- c_context
464
- );
454
+ xmlXPathRegisterFuncNS(c_context,
455
+ (const xmlChar *)"css-class", NOKOGIRI_BUILTIN_URI,
456
+ noko_xml_xpath_context_xpath_func_css_class);
457
+ xmlXPathRegisterFuncNS(c_context,
458
+ (const xmlChar *)"local-name-is", NOKOGIRI_BUILTIN_URI,
459
+ noko_xml_xpath_context_xpath_func_local_name_is);
460
+
461
+ rb_context = TypedData_Wrap_Struct(klass, &_noko_xml_xpath_context_type, c_context);
462
+
463
+ rb_iv_set(rb_context, "@registered_namespaces", rb_hash_new());
464
+ rb_iv_set(rb_context, "@registered_variables", rb_hash_new());
465
+
465
466
  return rb_context;
466
467
  }
467
468
 
469
+
470
+ /* :nodoc: */
471
+ static VALUE
472
+ noko_xml_xpath_context_set_node(VALUE rb_context, VALUE rb_node)
473
+ {
474
+ xmlNodePtr c_node;
475
+ xmlXPathContextPtr c_context;
476
+
477
+ TypedData_Get_Struct(rb_context, xmlXPathContext, &_noko_xml_xpath_context_type, c_context);
478
+ Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
479
+
480
+ c_context->doc = c_node->doc;
481
+ c_context->node = c_node;
482
+
483
+ return rb_node;
484
+ }
485
+
468
486
  void
469
487
  noko_init_xml_xpath_context(void)
470
488
  {
@@ -475,9 +493,10 @@ noko_init_xml_xpath_context(void)
475
493
 
476
494
  rb_undef_alloc_func(cNokogiriXmlXpathContext);
477
495
 
478
- rb_define_singleton_method(cNokogiriXmlXpathContext, "new", rb_xml_xpath_context_new, 1);
496
+ rb_define_singleton_method(cNokogiriXmlXpathContext, "new", noko_xml_xpath_context_new, 1);
479
497
 
480
- rb_define_method(cNokogiriXmlXpathContext, "evaluate", rb_xml_xpath_context_evaluate, -1);
481
- rb_define_method(cNokogiriXmlXpathContext, "register_variable", rb_xml_xpath_context_register_variable, 2);
482
- rb_define_method(cNokogiriXmlXpathContext, "register_ns", rb_xml_xpath_context_register_ns, 2);
498
+ rb_define_method(cNokogiriXmlXpathContext, "evaluate", noko_xml_xpath_context_evaluate, -1);
499
+ rb_define_method(cNokogiriXmlXpathContext, "register_variable", noko_xml_xpath_context_register_variable, 2);
500
+ rb_define_method(cNokogiriXmlXpathContext, "register_ns", noko_xml_xpath_context_register_ns, 2);
501
+ rb_define_method(cNokogiriXmlXpathContext, "node=", noko_xml_xpath_context_set_node, 1);
483
502
  }
Binary file
Binary file
Binary file
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Nokogiri
4
4
  # The version of Nokogiri you are using
5
- VERSION = "1.17.2"
5
+ VERSION = "1.18.0.rc1"
6
6
  end
@@ -207,35 +207,26 @@ module Nokogiri
207
207
 
208
208
  private
209
209
 
210
- def css_internal(node, rules, handler, ns)
211
- xpath_internal(node, css_rules_to_xpath(rules, ns), handler, ns, nil)
212
- end
213
-
214
- def xpath_internal(node, paths, handler, ns, binds)
215
- document = node.document
216
- return NodeSet.new(document) unless document
217
-
218
- if paths.length == 1
219
- return xpath_impl(node, paths.first, handler, ns, binds)
210
+ def extract_params(params) # :nodoc:
211
+ handler = params.find do |param|
212
+ ![Hash, String, Symbol].include?(param.class)
220
213
  end
214
+ params -= [handler] if handler
221
215
 
222
- NodeSet.new(document) do |combined|
223
- paths.each do |path|
224
- xpath_impl(node, path, handler, ns, binds).each { |set| combined << set }
225
- end
216
+ hashes = []
217
+ while Hash === params.last || params.last.nil?
218
+ hashes << params.pop
219
+ break if params.empty?
226
220
  end
227
- end
221
+ ns, binds = hashes.reverse
228
222
 
229
- def xpath_impl(node, path, handler, ns, binds)
230
- ctx = XPathContext.new(node)
231
- ctx.register_namespaces(ns)
232
- path = path.gsub("xmlns:", " :") unless Nokogiri.uses_libxml?
223
+ ns ||= document.root&.namespaces || {}
233
224
 
234
- binds&.each do |key, value|
235
- ctx.register_variable(key.to_s, value)
236
- end
225
+ [params, handler, ns, binds]
226
+ end
237
227
 
238
- ctx.evaluate(path, handler)
228
+ def css_internal(node, rules, handler, ns)
229
+ xpath_internal(node, css_rules_to_xpath(rules, ns), handler, ns, nil)
239
230
  end
240
231
 
241
232
  def css_rules_to_xpath(rules, ns)
@@ -254,22 +245,52 @@ module Nokogiri
254
245
  end.join(" | ")
255
246
  end
256
247
 
257
- def extract_params(params) # :nodoc:
258
- handler = params.find do |param|
259
- ![Hash, String, Symbol].include?(param.class)
248
+ def xpath_internal(node, paths, handler, ns, binds)
249
+ document = node.document
250
+ return NodeSet.new(document) unless document
251
+
252
+ if paths.length == 1
253
+ return xpath_impl(node, paths.first, handler, ns, binds)
260
254
  end
261
- params -= [handler] if handler
262
255
 
263
- hashes = []
264
- while Hash === params.last || params.last.nil?
265
- hashes << params.pop
266
- break if params.empty?
256
+ NodeSet.new(document) do |combined|
257
+ paths.each do |path|
258
+ xpath_impl(node, path, handler, ns, binds).each { |set| combined << set }
259
+ end
267
260
  end
268
- ns, binds = hashes.reverse
261
+ end
269
262
 
270
- ns ||= document.root&.namespaces || {}
263
+ def xpath_impl(node, path, handler, ns, binds)
264
+ get_xpath_context(node) do |context|
265
+ context.register_namespaces(ns)
266
+ context.register_variables(binds)
271
267
 
272
- [params, handler, ns, binds]
268
+ path = path.gsub("xmlns:", " :") unless Nokogiri.uses_libxml?
269
+
270
+ context.evaluate(path, handler)
271
+ end
272
+ end
273
+
274
+ if Nokogiri.uses_libxml? && ENV["NOKOGIRI_DEOPTIMIZE_XPATH"].nil? # env var is an escape hatch
275
+ # optimized path
276
+ def get_xpath_context(node)
277
+ context = Thread.current.thread_variable_get(:nokogiri_xpath_context)
278
+ if context
279
+ context.node = node
280
+ else
281
+ context = Thread.current.thread_variable_set(:nokogiri_xpath_context, XPathContext.new(node))
282
+ end
283
+
284
+ begin
285
+ yield context
286
+ ensure
287
+ context.reset
288
+ end
289
+ end
290
+ else
291
+ def get_xpath_context(node)
292
+ yield XPathContext.new(node)
293
+ end
273
294
  end
274
295
  end
275
296
  end
@@ -6,9 +6,42 @@ module Nokogiri
6
6
  ###
7
7
  # Register namespaces in +namespaces+
8
8
  def register_namespaces(namespaces)
9
- namespaces.each do |k, v|
10
- k = k.to_s.gsub(/.*:/, "") # strip off 'xmlns:' or 'xml:'
11
- register_ns(k, v)
9
+ namespaces.each do |key, value|
10
+ key = key.to_s.gsub(/.*:/, "") # strip off 'xmlns:' or 'xml:'
11
+
12
+ register_ns(key, value)
13
+ end
14
+ end
15
+
16
+ def register_variables(binds)
17
+ return if binds.nil?
18
+
19
+ binds.each do |key, value|
20
+ key = key.to_s
21
+
22
+ register_variable(key, value)
23
+ end
24
+ end
25
+
26
+ if Nokogiri.uses_libxml?
27
+ def reset
28
+ return unless
29
+
30
+ @registered_namespaces.each do |key, _|
31
+ register_ns(key, nil)
32
+ end
33
+ unless @registered_namespaces.empty?
34
+ warn "Nokogiri::XML::XPathContext#reset: unexpected registered namespaces: #{@registered_namespaces.keys}"
35
+ @registered_namespaces.clear
36
+ end
37
+
38
+ @registered_variables.each do |key, _|
39
+ register_variable(key, nil)
40
+ end
41
+ unless @registered_variables.empty?
42
+ warn "Nokogiri::XML::XPathContext#reset: unexpected registered variables: #{@registered_variables.keys}"
43
+ @registered_variables.clear
44
+ end
12
45
  end
13
46
  end
14
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.2
4
+ version: 1.18.0.rc1
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - Mike Dalessio
@@ -20,7 +20,7 @@ authors:
20
20
  autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
- date: 2024-12-12 00:00:00.000000000 Z
23
+ date: 2024-12-16 00:00:00.000000000 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: racc
@@ -202,10 +202,10 @@ files:
202
202
  - gumbo-parser/Makefile
203
203
  - gumbo-parser/THANKS
204
204
  - lib/nokogiri.rb
205
- - lib/nokogiri/3.0/nokogiri.bundle
206
205
  - lib/nokogiri/3.1/nokogiri.bundle
207
206
  - lib/nokogiri/3.2/nokogiri.bundle
208
207
  - lib/nokogiri/3.3/nokogiri.bundle
208
+ - lib/nokogiri/3.4/nokogiri.bundle
209
209
  - lib/nokogiri/class_resolver.rb
210
210
  - lib/nokogiri/css.rb
211
211
  - lib/nokogiri/css/node.rb
@@ -304,15 +304,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
304
304
  requirements:
305
305
  - - ">="
306
306
  - !ruby/object:Gem::Version
307
- version: '3.0'
307
+ version: '3.1'
308
308
  - - "<"
309
309
  - !ruby/object:Gem::Version
310
- version: 3.4.dev
310
+ version: 3.5.dev
311
311
  required_rubygems_version: !ruby/object:Gem::Requirement
312
312
  requirements:
313
- - - ">="
313
+ - - ">"
314
314
  - !ruby/object:Gem::Version
315
- version: '0'
315
+ version: 1.3.1
316
316
  requirements: []
317
317
  rubygems_version: 3.3.26
318
318
  signing_key: