nokogiri 1.19.3-java → 1.19.5-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +29 -0
  3. data/ext/java/nokogiri/XmlAttr.java +3 -0
  4. data/ext/java/nokogiri/XmlDocument.java +5 -1
  5. data/ext/java/nokogiri/XmlNode.java +69 -38
  6. data/ext/java/nokogiri/XmlNodeSet.java +19 -25
  7. data/ext/java/nokogiri/XmlReader.java +4 -1
  8. data/ext/java/nokogiri/XmlSchema.java +22 -9
  9. data/ext/java/nokogiri/XmlXpathContext.java +5 -15
  10. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +5 -7
  11. data/ext/java/nokogiri/internals/NokogiriHelpers.java +68 -0
  12. data/ext/java/nokogiri/internals/NokogiriXPathContext.java +37 -0
  13. data/ext/nokogiri/extconf.rb +1 -0
  14. data/ext/nokogiri/gumbo.c +83 -6
  15. data/ext/nokogiri/html4_document.c +10 -3
  16. data/ext/nokogiri/libxml2_polyfill.c +12 -0
  17. data/ext/nokogiri/nokogiri.c +90 -5
  18. data/ext/nokogiri/xml_attr.c +28 -23
  19. data/ext/nokogiri/xml_document.c +64 -30
  20. data/ext/nokogiri/xml_node.c +151 -52
  21. data/ext/nokogiri/xml_node_set.c +10 -10
  22. data/ext/nokogiri/xml_reader.c +198 -107
  23. data/ext/nokogiri/xml_sax_parser.c +3 -3
  24. data/ext/nokogiri/xml_sax_parser_context.c +38 -7
  25. data/ext/nokogiri/xml_sax_push_parser.c +12 -0
  26. data/ext/nokogiri/xml_xpath_context.c +135 -27
  27. data/ext/nokogiri/xslt_stylesheet.c +123 -27
  28. data/lib/nokogiri/css/parser.rb +35 -18
  29. data/lib/nokogiri/css/parser.y +35 -17
  30. data/lib/nokogiri/css/xpath_visitor.rb +71 -28
  31. data/lib/nokogiri/html5/document.rb +9 -0
  32. data/lib/nokogiri/html5/document_fragment.rb +16 -1
  33. data/lib/nokogiri/html5/node.rb +1 -1
  34. data/lib/nokogiri/html5.rb +16 -0
  35. data/lib/nokogiri/nokogiri.jar +0 -0
  36. data/lib/nokogiri/version/constant.rb +1 -1
  37. data/lib/nokogiri/version/info.rb +10 -0
  38. data/lib/nokogiri/xml/attr.rb +2 -0
  39. data/lib/nokogiri/xml/attribute_decl.rb +2 -1
  40. data/lib/nokogiri/xml/builder.rb +24 -32
  41. data/lib/nokogiri/xml/document.rb +4 -2
  42. data/lib/nokogiri/xml/dtd.rb +2 -1
  43. data/lib/nokogiri/xml/element_decl.rb +2 -1
  44. data/lib/nokogiri/xml/entity_decl.rb +2 -1
  45. data/lib/nokogiri/xml/node.rb +65 -12
  46. metadata +3 -2
@@ -115,14 +115,10 @@ relink_namespace(xmlNodePtr reparented)
115
115
  xmlNsPtr prev = NULL;
116
116
 
117
117
  while (curr) {
118
- xmlNsPtr ns = xmlSearchNsByHref(
119
- reparented->doc,
120
- reparented->parent,
121
- curr->href
122
- );
123
- /* If we find the namespace is already declared, remove it from this
124
- * definition list. */
125
- if (ns && ns != curr && xmlStrEqual(ns->prefix, curr->prefix)) {
118
+ xmlNsPtr ns = xmlSearchNs(reparented->doc, reparented->parent, curr->prefix);
119
+ /* If the parent already binds this prefix to the same href, remove it
120
+ * from this definition list. */
121
+ if (ns && ns != curr && xmlStrEqual(ns->href, curr->href)) {
126
122
  if (prev) {
127
123
  prev->next = curr->next;
128
124
  } else {
@@ -971,6 +967,10 @@ rb_xml_node_initialize_copy_with_args(VALUE rb_self, VALUE rb_other, VALUE rb_le
971
967
  xmlDocPtr c_new_parent_doc;
972
968
  VALUE rb_node_cache;
973
969
 
970
+ if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNode)) {
971
+ rb_raise(rb_eTypeError, "argument must be a kind of Nokogiri::XML::Node");
972
+ }
973
+
974
974
  Noko_Node_Get_Struct(rb_other, xmlNode, c_other);
975
975
  c_level = (int)NUM2INT(rb_level);
976
976
  c_new_parent_doc = noko_xml_document_unwrap(rb_new_parent_doc);
@@ -1228,6 +1228,29 @@ namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
1228
1228
  return Qfalse;
1229
1229
  }
1230
1230
 
1231
+ /* If a matching attribute node already exists, then xmlSetNsProp will destroy
1232
+ * the existing node's children. However, if Nokogiri has a node object
1233
+ * pointing to one of those children, we are left with a broken reference.
1234
+ *
1235
+ * We can avoid this by unlinking these nodes first.
1236
+ */
1237
+ static void
1238
+ unlink_wrapped_attr_children(xmlAttrPtr attr)
1239
+ {
1240
+ xmlNodePtr cur, next;
1241
+
1242
+ if (!attr || attr->type != XML_ATTRIBUTE_NODE) {
1243
+ return;
1244
+ }
1245
+ for (cur = attr->children; cur; cur = next) {
1246
+ next = cur->next;
1247
+ if (cur->_private) {
1248
+ noko_xml_document_pin_node(cur);
1249
+ xmlUnlinkNode(cur);
1250
+ }
1251
+ }
1252
+ }
1253
+
1231
1254
  /*
1232
1255
  * call-seq:
1233
1256
  * []=(property, value)
@@ -1237,31 +1260,36 @@ namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
1237
1260
  static VALUE
1238
1261
  set(VALUE self, VALUE property, VALUE value)
1239
1262
  {
1240
- xmlNodePtr node, cur;
1241
- xmlAttrPtr prop;
1263
+ xmlNodePtr node;
1264
+ xmlNsPtr ns = NULL;
1265
+ const xmlChar *name, *local_name, *c_value;
1266
+ xmlChar *prefix;
1267
+ int prefix_len;
1242
1268
  Noko_Node_Get_Struct(self, xmlNode, node);
1243
1269
 
1244
- /* If a matching attribute node already exists, then xmlSetProp will destroy
1245
- * the existing node's children. However, if Nokogiri has a node object
1246
- * pointing to one of those children, we are left with a broken reference.
1247
- *
1248
- * We can avoid this by unlinking these nodes first.
1249
- */
1250
1270
  if (node->type != XML_ELEMENT_NODE) {
1251
1271
  return (Qnil);
1252
1272
  }
1253
- prop = xmlHasProp(node, (xmlChar *)StringValueCStr(property));
1254
- if (prop && prop->children) {
1255
- for (cur = prop->children; cur; cur = cur->next) {
1256
- if (cur->_private) {
1257
- noko_xml_document_pin_node(cur);
1258
- xmlUnlinkNode(cur);
1259
- }
1273
+ name = (const xmlChar *)StringValueCStr(property);
1274
+ c_value = (const xmlChar *)StringValueCStr(value);
1275
+
1276
+ /* Resolve a QName the way xmlSetProp does, so that we find the same attribute it would replace. */
1277
+ local_name = xmlSplitQName3(name, &prefix_len);
1278
+ if (local_name) {
1279
+ prefix = xmlStrndup(name, prefix_len);
1280
+ if (!prefix) {
1281
+ rb_memerror();
1260
1282
  }
1283
+ ns = xmlSearchNs(node->doc, node, prefix);
1284
+ xmlFree(prefix);
1285
+ }
1286
+ if (!ns) {
1287
+ local_name = name;
1261
1288
  }
1262
1289
 
1263
- xmlSetProp(node, (xmlChar *)StringValueCStr(property),
1264
- (xmlChar *)StringValueCStr(value));
1290
+ unlink_wrapped_attr_children(xmlHasNsProp(node, local_name, ns ? ns->href : NULL));
1291
+
1292
+ xmlSetNsProp(node, ns, local_name, c_value);
1265
1293
 
1266
1294
  return value;
1267
1295
  }
@@ -1334,6 +1362,11 @@ set_namespace(VALUE self, VALUE namespace)
1334
1362
 
1335
1363
  xmlSetNs(node, ns);
1336
1364
 
1365
+ if (ns && node->type == XML_ELEMENT_NODE && !xmlSearchNs(node->doc, node, ns->prefix)) {
1366
+ xmlNsPtr definition = xmlNewNs(node, ns->href, ns->prefix);
1367
+ if (definition) { xmlSetNs(node, definition); }
1368
+ }
1369
+
1337
1370
  return self;
1338
1371
  }
1339
1372
 
@@ -1562,6 +1595,7 @@ set_lang(VALUE self_rb, VALUE lang_rb)
1562
1595
  Noko_Node_Get_Struct(self_rb, xmlNode, self);
1563
1596
  lang = (xmlChar *)StringValueCStr(lang_rb);
1564
1597
 
1598
+ unlink_wrapped_attr_children(xmlHasNsProp(self, BAD_CAST "lang", XML_XML_NAMESPACE));
1565
1599
  xmlNodeSetLang(self, lang);
1566
1600
 
1567
1601
  return Qnil ;
@@ -1740,7 +1774,7 @@ static inline void
1740
1774
  output_partial_string(VALUE out, char const *str, size_t length)
1741
1775
  {
1742
1776
  if (length) {
1743
- rb_enc_str_buf_cat(out, str, (long)length, rb_utf8_encoding());
1777
+ rb_enc_str_buf_cat(out, str, (rb_len_t)length, rb_utf8_encoding());
1744
1778
  }
1745
1779
  }
1746
1780
 
@@ -1830,9 +1864,9 @@ output_escaped_string(VALUE out, xmlChar const *start, bool attr)
1830
1864
  replaced_bytes = 2;
1831
1865
  } else if (attr && ch == '"') {
1832
1866
  replacement = """;
1833
- } else if (!attr && ch == '<') {
1867
+ } else if (ch == '<') {
1834
1868
  replacement = "&lt;";
1835
- } else if (!attr && ch == '>') {
1869
+ } else if (ch == '>') {
1836
1870
  replacement = "&gt;";
1837
1871
  } else {
1838
1872
  ++next;
@@ -1893,7 +1927,8 @@ static void
1893
1927
  output_node(
1894
1928
  VALUE out,
1895
1929
  xmlNodePtr node,
1896
- bool preserve_newline
1930
+ bool preserve_newline,
1931
+ bool scripting_enabled
1897
1932
  )
1898
1933
  {
1899
1934
  static char const *const VOID_ELEMENTS[] = {
@@ -1902,9 +1937,11 @@ output_node(
1902
1937
  };
1903
1938
 
1904
1939
  static char const *const UNESCAPED_TEXT_ELEMENTS[] = {
1905
- "style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext", "noscript",
1940
+ "style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext",
1906
1941
  };
1907
1942
 
1943
+ static char const *const NOSCRIPT_ELEMENT[] = { "noscript" };
1944
+
1908
1945
  switch (node->type) {
1909
1946
  case XML_ELEMENT_NODE:
1910
1947
  // Serialize the start tag.
@@ -1914,7 +1951,7 @@ output_node(
1914
1951
  // Add attributes.
1915
1952
  for (xmlAttrPtr attr = node->properties; attr; attr = attr->next) {
1916
1953
  output_char(out, ' ');
1917
- output_node(out, (xmlNodePtr)attr, preserve_newline);
1954
+ output_node(out, (xmlNodePtr)attr, preserve_newline, scripting_enabled);
1918
1955
  }
1919
1956
  output_char(out, '>');
1920
1957
 
@@ -1924,7 +1961,7 @@ output_node(
1924
1961
  output_char(out, '\n');
1925
1962
  }
1926
1963
  for (xmlNodePtr child = node->children; child; child = child->next) {
1927
- output_node(out, child, preserve_newline);
1964
+ output_node(out, child, preserve_newline, scripting_enabled);
1928
1965
  }
1929
1966
  output_string(out, "</");
1930
1967
  output_tagname(out, node);
@@ -1950,8 +1987,9 @@ output_node(
1950
1987
 
1951
1988
  case XML_TEXT_NODE:
1952
1989
  if (node->parent
1953
- && is_one_of(node->parent, UNESCAPED_TEXT_ELEMENTS,
1954
- sizeof UNESCAPED_TEXT_ELEMENTS / sizeof UNESCAPED_TEXT_ELEMENTS[0])) {
1990
+ && (is_one_of(node->parent, UNESCAPED_TEXT_ELEMENTS,
1991
+ sizeof UNESCAPED_TEXT_ELEMENTS / sizeof UNESCAPED_TEXT_ELEMENTS[0])
1992
+ || (scripting_enabled && is_one_of(node->parent, NOSCRIPT_ELEMENT, 1)))) {
1955
1993
  output_string(out, (char const *)node->content);
1956
1994
  } else {
1957
1995
  output_escaped_string(out, node->content, false);
@@ -1987,7 +2025,7 @@ output_node(
1987
2025
  case XML_DOCUMENT_FRAG_NODE:
1988
2026
  case XML_HTML_DOCUMENT_NODE:
1989
2027
  for (xmlNodePtr child = node->children; child; child = child->next) {
1990
- output_node(out, child, preserve_newline);
2028
+ output_node(out, child, preserve_newline, scripting_enabled);
1991
2029
  }
1992
2030
  break;
1993
2031
 
@@ -2000,13 +2038,14 @@ output_node(
2000
2038
  static VALUE
2001
2039
  html_standard_serialize(
2002
2040
  VALUE self,
2003
- VALUE preserve_newline
2041
+ VALUE preserve_newline,
2042
+ VALUE scripting_enabled
2004
2043
  )
2005
2044
  {
2006
2045
  xmlNodePtr node;
2007
2046
  Noko_Node_Get_Struct(self, xmlNode, node);
2008
2047
  VALUE output = rb_str_buf_new(4096);
2009
- output_node(output, node, RTEST(preserve_newline));
2048
+ output_node(output, node, RTEST(preserve_newline), RTEST(scripting_enabled));
2010
2049
  return output;
2011
2050
  }
2012
2051
 
@@ -2150,25 +2189,20 @@ compare(VALUE self, VALUE _other)
2150
2189
 
2151
2190
 
2152
2191
  /*
2153
- * call-seq:
2154
- * process_xincludes(flags)
2155
- *
2156
- * Loads and substitutes all xinclude elements below the node. The
2157
- * parser context will be initialized with +flags+.
2192
+ * Run XInclude substitution over the tree rooted at +c_node+, with the parser context initialized
2193
+ * from +c_flags+. Collects libxml2's structured errors and raises Nokogiri::XML::SyntaxError (or
2194
+ * RuntimeError) on failure.
2158
2195
  */
2159
- static VALUE
2160
- noko_xml_node__process_xincludes(VALUE rb_node, VALUE rb_flags)
2196
+ static void
2197
+ _noko_xml_node_process_xinclude_subtree(xmlNodePtr c_node, int c_flags)
2161
2198
  {
2162
2199
  int status ;
2163
- xmlNodePtr c_node;
2164
2200
  VALUE rb_errors = rb_ary_new();
2165
2201
  libxmlStructuredErrorHandlerState handler_state;
2166
2202
 
2167
- Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
2168
-
2169
2203
  noko__structured_error_func_save_and_set(&handler_state, (void *)rb_errors, noko__error_array_pusher);
2170
2204
 
2171
- status = xmlXIncludeProcessTreeFlags(c_node, (int)NUM2INT(rb_flags));
2205
+ status = xmlXIncludeProcessTreeFlags(c_node, c_flags);
2172
2206
 
2173
2207
  noko__structured_error_func_restore(&handler_state);
2174
2208
 
@@ -2181,11 +2215,77 @@ noko_xml_node__process_xincludes(VALUE rb_node, VALUE rb_flags)
2181
2215
  rb_raise(rb_eRuntimeError, "Could not perform xinclude substitution");
2182
2216
  }
2183
2217
  }
2218
+ }
2219
+
2220
+
2221
+ /*
2222
+ * Whether +c_node+ is an <xi:include> element in either the 2001 or 2003 XInclude namespace.
2223
+ */
2224
+ static int
2225
+ _noko_xml_node_xinclude_element_p(xmlNodePtr c_node)
2226
+ {
2227
+ return c_node->type == XML_ELEMENT_NODE
2228
+ && xmlStrEqual(c_node->name, XINCLUDE_NODE)
2229
+ && c_node->ns != NULL
2230
+ && (xmlStrEqual(c_node->ns->href, XINCLUDE_NS) || xmlStrEqual(c_node->ns->href, XINCLUDE_OLD_NS));
2231
+ }
2232
+
2233
+
2234
+ /*
2235
+ * call-seq:
2236
+ * process_xincludes(flags)
2237
+ *
2238
+ * Loads and substitutes all xinclude elements below the node. The
2239
+ * parser context will be initialized with +flags+.
2240
+ */
2241
+ static VALUE
2242
+ noko_xml_node__process_xincludes(VALUE rb_node, VALUE rb_flags)
2243
+ {
2244
+ xmlNodePtr c_node;
2245
+
2246
+ Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
2247
+
2248
+ if (c_node->parent == NULL && _noko_xml_node_xinclude_element_p(c_node)) {
2249
+ rb_raise(rb_eRuntimeError, "cannot process XInclude on an unlinked <xi:include> node");
2250
+ }
2251
+
2252
+ _noko_xml_node_process_xinclude_subtree(c_node, (int)NUM2INT(rb_flags));
2184
2253
 
2185
2254
  return rb_node;
2186
2255
  }
2187
2256
 
2188
2257
 
2258
+ /*
2259
+ * Process this single <xi:include> node, substituting an unwrapped copy of it in its place so
2260
+ * that libxml2 frees the copy. This node is unlinked and pinned to the document, so any Ruby
2261
+ * wrapper for it (or for its descendants or namespaces) keeps pointing at valid memory. The
2262
+ * parser context is initialized with +flags+.
2263
+ */
2264
+ static VALUE
2265
+ noko_xml_node__safe_process_xinclude(VALUE rb_node, VALUE rb_flags)
2266
+ {
2267
+ xmlNodePtr c_node, c_copy;
2268
+
2269
+ Noko_Node_Get_Struct(rb_node, xmlNode, c_node);
2270
+
2271
+ if (c_node->parent == NULL) {
2272
+ rb_raise(rb_eRuntimeError, "cannot process XInclude on an unlinked <xi:include> node");
2273
+ }
2274
+
2275
+ c_copy = xmlDocCopyNode(c_node, c_node->doc, 1);
2276
+ if (c_copy == NULL) {
2277
+ rb_raise(rb_eRuntimeError, "Could not copy node for xinclude substitution");
2278
+ }
2279
+
2280
+ xmlReplaceNode(c_node, c_copy);
2281
+ noko_xml_document_pin_node(c_node);
2282
+
2283
+ _noko_xml_node_process_xinclude_subtree(c_copy, (int)NUM2INT(rb_flags));
2284
+
2285
+ return Qnil;
2286
+ }
2287
+
2288
+
2189
2289
  /* TODO: DOCUMENT ME */
2190
2290
  static VALUE
2191
2291
  in_context(VALUE self, VALUE _str, VALUE _options)
@@ -2286,9 +2386,7 @@ in_context(VALUE self, VALUE _str, VALUE _options)
2286
2386
  VALUE
2287
2387
  rb_xml_node_data_ptr_eh(VALUE self)
2288
2388
  {
2289
- xmlNodePtr c_node;
2290
- Noko_Node_Get_Struct(self, xmlNode, c_node);
2291
- return c_node ? Qtrue : Qfalse;
2389
+ return DATA_PTR(self) ? Qtrue : Qfalse;
2292
2390
  }
2293
2391
 
2294
2392
  VALUE
@@ -2438,6 +2536,7 @@ noko_init_xml_node(void)
2438
2536
  rb_define_method(cNokogiriXmlNode, "unlink", unlink_node, 0);
2439
2537
 
2440
2538
  rb_define_protected_method(cNokogiriXmlNode, "initialize_copy_with_args", rb_xml_node_initialize_copy_with_args, 3);
2539
+ rb_define_protected_method(cNokogiriXmlNode, "safe_process_xinclude", noko_xml_node__safe_process_xinclude, 1);
2441
2540
 
2442
2541
  rb_define_private_method(cNokogiriXmlNode, "add_child_node", add_child, 1);
2443
2542
  rb_define_private_method(cNokogiriXmlNode, "add_next_sibling_node", add_next_sibling, 1);
@@ -2448,7 +2547,7 @@ noko_init_xml_node(void)
2448
2547
  rb_define_private_method(cNokogiriXmlNode, "in_context", in_context, 2);
2449
2548
  rb_define_private_method(cNokogiriXmlNode, "native_write_to", native_write_to, 4);
2450
2549
  rb_define_private_method(cNokogiriXmlNode, "prepend_newline?", rb_prepend_newline, 0);
2451
- rb_define_private_method(cNokogiriXmlNode, "html_standard_serialize", html_standard_serialize, 1);
2550
+ rb_define_private_method(cNokogiriXmlNode, "html_standard_serialize", html_standard_serialize, 2);
2452
2551
  rb_define_private_method(cNokogiriXmlNode, "process_xincludes", noko_xml_node__process_xincludes, 1);
2453
2552
  rb_define_private_method(cNokogiriXmlNode, "replace_node", replace, 1);
2454
2553
  rb_define_private_method(cNokogiriXmlNode, "set", set, 2);
@@ -298,13 +298,13 @@ minus(VALUE rb_self, VALUE rb_other)
298
298
 
299
299
 
300
300
  static VALUE
301
- index_at(VALUE rb_self, long offset)
301
+ index_at(VALUE rb_self, rb_len_t offset)
302
302
  {
303
303
  xmlNodeSetPtr c_self;
304
304
 
305
305
  TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
306
306
 
307
- if (offset >= c_self->nodeNr || abs((int)offset) > c_self->nodeNr) {
307
+ if (offset >= c_self->nodeNr || offset < -c_self->nodeNr) {
308
308
  return Qnil;
309
309
  }
310
310
 
@@ -314,9 +314,9 @@ index_at(VALUE rb_self, long offset)
314
314
  }
315
315
 
316
316
  static VALUE
317
- subseq(VALUE rb_self, long beg, long len)
317
+ subseq(VALUE rb_self, rb_len_t beg, rb_len_t len)
318
318
  {
319
- long j;
319
+ rb_len_t j;
320
320
  xmlNodeSetPtr c_self;
321
321
  xmlNodeSetPtr new_set ;
322
322
 
@@ -355,14 +355,14 @@ static VALUE
355
355
  slice(int argc, VALUE *argv, VALUE rb_self)
356
356
  {
357
357
  VALUE arg ;
358
- long beg, len ;
358
+ rb_len_t beg, len ;
359
359
  xmlNodeSetPtr c_self;
360
360
 
361
361
  TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
362
362
 
363
363
  if (argc == 2) {
364
- beg = NUM2LONG(argv[0]);
365
- len = NUM2LONG(argv[1]);
364
+ beg = RB_NUM2LEN(argv[0]);
365
+ len = RB_NUM2LEN(argv[1]);
366
366
  if (beg < 0) {
367
367
  beg += c_self->nodeNr ;
368
368
  }
@@ -375,11 +375,11 @@ slice(int argc, VALUE *argv, VALUE rb_self)
375
375
  arg = argv[0];
376
376
 
377
377
  if (FIXNUM_P(arg)) {
378
- return index_at(rb_self, FIX2LONG(arg));
378
+ return index_at(rb_self, RB_FIX2LEN(arg));
379
379
  }
380
380
 
381
381
  /* if arg is Range */
382
- switch (rb_range_beg_len(arg, &beg, &len, (long)c_self->nodeNr, 0)) {
382
+ switch (rb_range_beg_len(arg, &beg, &len, (rb_len_t)c_self->nodeNr, 0)) {
383
383
  case Qfalse:
384
384
  break;
385
385
  case Qnil:
@@ -388,7 +388,7 @@ slice(int argc, VALUE *argv, VALUE rb_self)
388
388
  return subseq(rb_self, beg, len);
389
389
  }
390
390
 
391
- return index_at(rb_self, NUM2LONG(arg));
391
+ return index_at(rb_self, RB_NUM2LEN(arg));
392
392
  }
393
393
 
394
394