nokogiri 1.17.1-x64-mingw-ucrt → 1.18.0.rc1-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/LICENSE-DEPENDENCIES.md +6 -6
- data/README.md +4 -5
- data/ext/nokogiri/extconf.rb +5 -13
- data/ext/nokogiri/xml_xpath_context.c +118 -99
- data/lib/nokogiri/3.1/nokogiri.so +0 -0
- data/lib/nokogiri/3.2/nokogiri.so +0 -0
- data/lib/nokogiri/3.3/nokogiri.so +0 -0
- data/lib/nokogiri/3.4/nokogiri.so +0 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/xml/searchable.rb +55 -34
- data/lib/nokogiri/xml/xpath_context.rb +36 -3
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65c3725dbaabc82f774646cf03fbd55aab3b6aeb12c6b1d0c0c3e2cbde2c71c4
|
4
|
+
data.tar.gz: 8e92ddd9ef61fccfbfee2b9a061301284a09a8d807e15959afa30934c0670537
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b52419005715c1e5d983d3f704f63b5403bef5bac8a098fcdf96d57d51d3425cc239d3b9c22bf773394c8cd41fd211dbf0d32f15d2d2d4807383f5b2e663109e
|
7
|
+
data.tar.gz: 5b466519420bc3908feaae286965935b6f439fc07cb962b13a121e57e74bffaddcfa65855f29c779fefe5a1c6ac08e74cdea2a145f96a524b3a5e023c6bc9612
|
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.
|
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.
|
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.
|
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.
|
37
|
+
gem "rdoc", "6.9.0"
|
38
38
|
end
|
data/LICENSE-DEPENDENCIES.md
CHANGED
@@ -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", "
|
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 ("
|
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", "
|
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 "
|
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 ("
|
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-
|
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.
|
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
|
-
- `
|
135
|
-
- `aarch64-linux
|
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: `
|
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'`.
|
data/ext/nokogiri/extconf.rb
CHANGED
@@ -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", "-
|
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", "-
|
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", "-
|
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
|
-
|
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
|
-
|
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
|
21
|
+
static const rb_data_type_t _noko_xml_xpath_context_type = {
|
22
22
|
.wrap_struct_name = "xmlXPathContext",
|
23
23
|
.function = {
|
24
|
-
.dfree =
|
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
|
-
|
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
|
65
|
+
/* xmlXPathFunction to wrap _noko_xml_xpath_context__css_class() */
|
66
66
|
static void
|
67
|
-
|
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 (
|
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
|
-
|
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
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
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
|
-
|
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
|
-
|
174
|
+
if (NIL_P(value)) {
|
175
|
+
xmlValue = NULL;
|
176
|
+
} else {
|
177
|
+
xmlValue = xmlXPathNewCString(StringValueCStr(value));
|
178
|
+
}
|
171
179
|
|
172
|
-
xmlXPathRegisterVariable(
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
-
|
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] =
|
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
|
-
|
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
|
-
|
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.
|
336
|
+
c_name, c_name); // TODO deprecated in v1.15.0, remove in v1.19.0
|
326
337
|
}
|
327
|
-
return
|
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
|
-
|
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("
|
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
|
-
|
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
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
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
|
-
|
385
|
-
|
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
|
-
|
393
|
+
c_expression_str = (xmlChar *)StringValueCStr(rb_expression);
|
389
394
|
|
390
|
-
if (Qnil !=
|
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 *)
|
397
|
+
c_context->userData = (void *)rb_function_lookup_handler;
|
393
398
|
xmlXPathRegisterFuncLookup(
|
394
399
|
c_context,
|
395
|
-
|
396
|
-
(void *)
|
400
|
+
_noko_xml_xpath_context_handler_lookup,
|
401
|
+
(void *)rb_function_lookup_handler
|
397
402
|
);
|
398
403
|
}
|
399
404
|
|
400
|
-
xmlSetStructuredErrorFunc((void *)
|
401
|
-
xmlSetGenericErrorFunc((void *)
|
405
|
+
xmlSetStructuredErrorFunc((void *)rb_errors, noko__error_array_pusher);
|
406
|
+
xmlSetGenericErrorFunc((void *)rb_errors, _noko_xml_xpath_context__generic_exception_pusher);
|
402
407
|
|
403
|
-
|
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
|
-
|
409
|
-
|
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
|
-
|
413
|
-
if (
|
414
|
-
|
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(
|
424
|
+
xmlXPathFreeNodeSetList(c_xpath_object);
|
418
425
|
|
419
|
-
return
|
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
|
-
|
436
|
+
noko_xml_xpath_context_new(VALUE klass, VALUE rb_node)
|
430
437
|
{
|
431
|
-
xmlNodePtr
|
438
|
+
xmlNodePtr c_node;
|
432
439
|
xmlXPathContextPtr c_context;
|
433
440
|
VALUE rb_context;
|
434
441
|
|
435
|
-
Noko_Node_Get_Struct(rb_node, xmlNode,
|
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(
|
443
|
-
c_context->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
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
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",
|
496
|
+
rb_define_singleton_method(cNokogiriXmlXpathContext, "new", noko_xml_xpath_context_new, 1);
|
479
497
|
|
480
|
-
rb_define_method(cNokogiriXmlXpathContext, "evaluate",
|
481
|
-
rb_define_method(cNokogiriXmlXpathContext, "register_variable",
|
482
|
-
rb_define_method(cNokogiriXmlXpathContext, "register_ns",
|
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
|
Binary file
|
@@ -207,35 +207,26 @@ module Nokogiri
|
|
207
207
|
|
208
208
|
private
|
209
209
|
|
210
|
-
def
|
211
|
-
|
212
|
-
|
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
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
216
|
+
hashes = []
|
217
|
+
while Hash === params.last || params.last.nil?
|
218
|
+
hashes << params.pop
|
219
|
+
break if params.empty?
|
226
220
|
end
|
227
|
-
|
221
|
+
ns, binds = hashes.reverse
|
228
222
|
|
229
|
-
|
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
|
-
|
235
|
-
|
236
|
-
end
|
225
|
+
[params, handler, ns, binds]
|
226
|
+
end
|
237
227
|
|
238
|
-
|
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
|
258
|
-
|
259
|
-
|
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
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
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
|
-
|
261
|
+
end
|
269
262
|
|
270
|
-
|
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
|
-
|
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 |
|
10
|
-
|
11
|
-
|
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.
|
4
|
+
version: 1.18.0.rc1
|
5
5
|
platform: x64-mingw-ucrt
|
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-
|
23
|
+
date: 2024-12-16 00:00:00.000000000 Z
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: racc
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- lib/nokogiri/3.1/nokogiri.so
|
206
206
|
- lib/nokogiri/3.2/nokogiri.so
|
207
207
|
- lib/nokogiri/3.3/nokogiri.so
|
208
|
+
- lib/nokogiri/3.4/nokogiri.so
|
208
209
|
- lib/nokogiri/class_resolver.rb
|
209
210
|
- lib/nokogiri/css.rb
|
210
211
|
- lib/nokogiri/css/node.rb
|
@@ -306,12 +307,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
306
307
|
version: '3.1'
|
307
308
|
- - "<"
|
308
309
|
- !ruby/object:Gem::Version
|
309
|
-
version: 3.
|
310
|
+
version: 3.5.dev
|
310
311
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
311
312
|
requirements:
|
312
|
-
- - "
|
313
|
+
- - ">"
|
313
314
|
- !ruby/object:Gem::Version
|
314
|
-
version:
|
315
|
+
version: 1.3.1
|
315
316
|
requirements: []
|
316
317
|
rubygems_version: 3.3.26
|
317
318
|
signing_key:
|