makiri 0.17.0.rc2-aarch64-linux → 0.17.0.rc3-aarch64-linux
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +84 -1
- data/NOKOGIRI_DIFFERENCES.md +33 -6
- data/README.md +12 -5
- data/lib/makiri/3.3/makiri.so +0 -0
- data/lib/makiri/3.4/makiri.so +0 -0
- data/lib/makiri/4.0/makiri.so +0 -0
- data/lib/makiri/html/document.rb +12 -2
- data/lib/makiri/node.rb +19 -3
- data/lib/makiri/node_set.rb +4 -3
- data/lib/makiri/version.rb +1 -1
- data/lib/makiri/xml/node_methods.rb +2 -28
- data/lib/makiri/xpath_context.rb +10 -11
- data/lib/makiri.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8728490c295f3658f875094b776c35419243cef2fc50840b0afa7bbac8cbf53d
|
|
4
|
+
data.tar.gz: 316811bde14173168583788f333ae261a5e785056b2da1bfd5f86bd2da5c15e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f8fa348eaa40cad07d20be02b3de24fb5f8cf235c155c0e800dbb644eb258561a3c516007d916c003a10f061d11c78ca870542f729528761723079b6b9263ce9
|
|
7
|
+
data.tar.gz: ddb0f4cabc405dabcea36185ec84d58103adb8b0bdd9327aaa31ffc981193ff1dd5d71033a5b788b63c9020b9c361de2f50ef53c668f6586a7b0dec828ebdc4c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,89 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [
|
|
3
|
+
## [0.17.0.rc3] - 2026-11-08
|
|
4
|
+
|
|
5
|
+
### Security
|
|
6
|
+
|
|
7
|
+
* An HTML parse stops with `Makiri::Error` ("document size limit
|
|
8
|
+
exceeded") once the document it builds passes `max_amplification:` times
|
|
9
|
+
its input (default 256, never less than 64 MiB), so a crafted input can no
|
|
10
|
+
longer build a document far larger than itself; ordinary documents build
|
|
11
|
+
10-50 times theirs. The keyword is taken by `Makiri::HTML`,
|
|
12
|
+
`Document#fragment` and `DocumentFragment.parse`, and a negative value
|
|
13
|
+
lifts the limit. `inner_html=` and `outer_html=` use the default.
|
|
14
|
+
* A selector, an XPath expression, a name or text is checked to be UTF-8 by
|
|
15
|
+
Makiri itself, on its own copy of the bytes, rather than trusted on the
|
|
16
|
+
String's cached coderange, which another C extension could leave wrong.
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
* Makiri can be used outside the main Ractor. Each Ractor parses, queries,
|
|
21
|
+
edits and writes its own documents, in parallel with the others: XPath,
|
|
22
|
+
which holds the GVL and so does not scale across threads, scales across
|
|
23
|
+
Ractors. A Document, a node, a NodeSet or an XPathContext cannot be
|
|
24
|
+
shared with, copied to or moved to another Ractor.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
* A source install needs Rust 1.95 or newer (it was 1.84). Binary gems
|
|
29
|
+
need no toolchain.
|
|
30
|
+
* An unknown keyword is `ArgumentError` in `DocumentFragment.parse`,
|
|
31
|
+
`Document#fragment`, `to_html`, `inner_html`, `outer_html`, `to_xml` and
|
|
32
|
+
`canonicalize`, as it already was in `Makiri::HTML` and `Makiri::XML`;
|
|
33
|
+
a misspelt one was ignored. `#xpath`, `#at_xpath` and `XPathContext.new`
|
|
34
|
+
read their other keywords as namespace bindings, as before.
|
|
35
|
+
* HTML `to_html`, `to_s`, `outer_html` and `inner_html` take `encoding:`
|
|
36
|
+
naming UTF-8 (a String, a Symbol or an `Encoding`), which code written
|
|
37
|
+
for Nokogiri passes, and refuse any other with `ArgumentError`: HTML is
|
|
38
|
+
written as UTF-8 alone. `NodeSet#to_html` passes its keywords to each
|
|
39
|
+
node's.
|
|
40
|
+
* An exception message is at most 256 bytes; one quoting a longer selector,
|
|
41
|
+
expression or name ends in `...`.
|
|
42
|
+
* `XPathContext#node=`, `#register_namespace(s)` and `#register_variable(s)`
|
|
43
|
+
on a frozen context raise `FrozenError`.
|
|
44
|
+
* A namespace binding given as a keyword (`doc.xpath(expr, k => uri)`) must
|
|
45
|
+
have a Symbol or plain String key; a String subclass raises `TypeError`.
|
|
46
|
+
`XPathContext#register_namespaces` takes a Hash alone; anything else is
|
|
47
|
+
`TypeError`.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
* `Node#search` and `#at` read a string as XPath when it names an axis
|
|
52
|
+
(`ancestor::div`) outside a quoted string, not for any `::`: a selector
|
|
53
|
+
with `::` in an attribute value (`a[title='a::b']`) answered nothing, and
|
|
54
|
+
one with a pseudo-element (`p::before`) raised
|
|
55
|
+
`Makiri::XPath::SyntaxError`.
|
|
56
|
+
* `Makiri::XML`'s `#css`, `#at_css` and `#matches?` take a selector as
|
|
57
|
+
`Makiri::HTML`'s do, a `String` or a `Symbol`, anything else a
|
|
58
|
+
`TypeError`. They called `to_s` on it, so `nil` raised
|
|
59
|
+
`Makiri::CSS::SyntaxError` and `1` was the selector `"1"`.
|
|
60
|
+
* A fragment's String `context:` naming no built-in tag (`"my-el"`) is
|
|
61
|
+
`ArgumentError` in every document; `Document#fragment` took one when the
|
|
62
|
+
document already held such an element. `"SVG"` and `"MATH"` name the SVG
|
|
63
|
+
and MathML roots in any case, as an HTML tag does; only the lower-case
|
|
64
|
+
names did.
|
|
65
|
+
* Inserting a fragment one of whose children is frozen raises
|
|
66
|
+
`FrozenError`, as inserting a frozen node does, in HTML and XML, and
|
|
67
|
+
inserts nothing.
|
|
68
|
+
* An XML Document reports what its factories (`create_element`,
|
|
69
|
+
`create_text_node`, `clone_node`, ...) grow it by to the GC, as an HTML
|
|
70
|
+
one does, so a loop that only makes nodes is collected on memory pressure.
|
|
71
|
+
* An XML document that begins with a UTF-16 byte order mark and declares
|
|
72
|
+
`encoding="UTF-16"`, as XML 1.0 writes one, parses (UTF-32's too), and so
|
|
73
|
+
does `to_xml(encoding: "UTF-16")`'s output; both raised
|
|
74
|
+
`Makiri::XML::SyntaxError`.
|
|
75
|
+
* An XML document declaring `encoding="US-ASCII"` that holds a character
|
|
76
|
+
past ASCII raises `Makiri::XML::SyntaxError`, a UTF-8 String or a byte
|
|
77
|
+
order mark included; the character was read.
|
|
78
|
+
* XML `to_xml(encoding: "US-ASCII")` writes a character past ASCII as a
|
|
79
|
+
character reference, in a US-ASCII String. It wrote the UTF-8 bytes
|
|
80
|
+
under the US-ASCII declaration, which `Makiri::XML` then refused.
|
|
81
|
+
* `to_xml(encoding:)` naming an encoding other than UTF-8 raises
|
|
82
|
+
`Makiri::Error` when an element or attribute name, a doctype, a comment,
|
|
83
|
+
a CDATA section or a processing instruction holds a character the
|
|
84
|
+
encoding has no form for. A character reference is markup only in text
|
|
85
|
+
and attribute values; written elsewhere, it made a name ill-formed and
|
|
86
|
+
changed a comment's text.
|
|
4
87
|
|
|
5
88
|
## [0.17.0.rc2] - 2026-10-24
|
|
6
89
|
|
data/NOKOGIRI_DIFFERENCES.md
CHANGED
|
@@ -50,11 +50,36 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
|
|
|
50
50
|
* An index is an `Integer`: `node_set[1.5]` and a Range with a Float end
|
|
51
51
|
are a `TypeError`, where Nokogiri (as `Array#[]`) truncates them.
|
|
52
52
|
|
|
53
|
+
* Namespace bindings: a Hash key is read as a prefix, with only `xmlns:` taken off
|
|
54
|
+
* `xpath(expr, ns)`, `css(rule, ns)` and `XPathContext#register_namespaces`
|
|
55
|
+
bind `p` for a key `"xmlns:p"`, so the Hash `Node#namespaces` returns can
|
|
56
|
+
be passed as it is, as in Nokogiri. Nokogiri takes off everything up to the
|
|
57
|
+
last `:` of any key (`"xml:p"`, `"a:b:p"` bind `p`); Makiri reads any other
|
|
58
|
+
key as the prefix itself.
|
|
59
|
+
* Keys and values are not converted: a key is a `String` or a `Symbol`, a URI
|
|
60
|
+
a `String`, and anything else is a `TypeError`. Nokogiri's
|
|
61
|
+
`register_namespaces` and `register_variables` call `to_s` on each key, so
|
|
62
|
+
an Integer key binds `"1"` there.
|
|
63
|
+
* `register_namespace` with a single prefix takes `"xmlns:p"` as it is, in
|
|
64
|
+
both.
|
|
65
|
+
|
|
66
|
+
* `Node#search` / `#at` send more strings to XPath
|
|
67
|
+
* Both treat a string that starts with `/`, `./` or `..`, or is `.` alone,
|
|
68
|
+
as XPath. Makiri also treats one that starts with `(` or `@`, or names an
|
|
69
|
+
axis outside a quoted string, as XPath (`(//a)[1]`, `@href`, `child::p`);
|
|
70
|
+
a CSS pseudo-element (`p::before`) or a `::` in an attribute value stays
|
|
71
|
+
CSS. Nokogiri sends those to its CSS translator, which raises
|
|
72
|
+
`CSS::SyntaxError` for `(//a)[1]` and `child::p`; `@href` happens to come
|
|
73
|
+
out as the same attribute search.
|
|
74
|
+
|
|
53
75
|
* There are no custom XPath functions
|
|
54
76
|
* Nokogiri answers a function XPath does not define by calling a method of
|
|
55
77
|
a handler object (`xpath("my-fn(.)", handler)`). Makiri runs no Ruby while
|
|
56
78
|
it evaluates: a call to a function XPath 1.0 does not define is an
|
|
57
|
-
`XPath::SyntaxError`, and a handler argument is an `ArgumentError`.
|
|
79
|
+
`XPath::SyntaxError`, and a handler argument is an `ArgumentError`. The
|
|
80
|
+
exception is Nokogiri's own builtins, `css-class` and `local-name-is`,
|
|
81
|
+
which answer under a prefix bound to Nokogiri's builtin namespace
|
|
82
|
+
(`https://www.nokogiri.org/default_ns/ruby/builtins`).
|
|
58
83
|
|
|
59
84
|
* A number literal is read as the nearest double; libxml2's own reader is not
|
|
60
85
|
correctly rounded for a literal with more digits than a double holds, so
|
|
@@ -224,7 +249,7 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
|
|
|
224
249
|
not: its parsed contents live in the separate fragment `Element#content_fragment`
|
|
225
250
|
returns, `template.children` is empty, and `inner_html` / `inner_html=`
|
|
226
251
|
special-case the contents (the WHATWG DOM special-cases `innerHTML` alone;
|
|
227
|
-
`
|
|
252
|
+
`add_child`, `content=`, and `children` act on the element's own empty
|
|
228
253
|
children, as the specification says). Nokogiri treats `<template>` as an
|
|
229
254
|
ordinary element, with the parsed nodes as its children, so
|
|
230
255
|
`template.inner_html` and `template.children` answer the other way round and
|
|
@@ -306,8 +331,10 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
|
|
|
306
331
|
`div`, since the selector is matched against the whole tree and only the
|
|
307
332
|
results are kept to descendants. `Nokogiri::HTML5` and `Nokogiri::XML` scope
|
|
308
333
|
the selector to the node (`#c` cannot be the `div`), and so did
|
|
309
|
-
`Makiri::XML` up to 0.16.
|
|
310
|
-
|
|
334
|
+
`Makiri::XML` up to 0.16. `:scope` is the node the query is made from, as in
|
|
335
|
+
a browser (`at_css("#c").css(":scope > p")`, and the document element when
|
|
336
|
+
the query is made from a document), for a match scoped to it; XPath from the
|
|
337
|
+
node (`xpath(".//div//p")`) is the other way.
|
|
311
338
|
* The attribute case modifiers (`[a="x" i]`, `[a="x" s]`) are supported on
|
|
312
339
|
both representations. Nokogiri refuses both on either.
|
|
313
340
|
* The form-state and link pseudo-classes (`:checked`, `:disabled`,
|
|
@@ -348,8 +375,8 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
|
|
|
348
375
|
disabled (its children are elements, not raw text) and escaping is what makes
|
|
349
376
|
that round-trip; `Nokogiri::HTML5` writes it literally and contradicts its own
|
|
350
377
|
parser there.
|
|
351
|
-
* An Attr serializes to the empty string (`attr.to_s`,
|
|
352
|
-
|
|
378
|
+
* An Attr serializes to the empty string (`attr.to_s`, `NodeSet#to_s` over
|
|
379
|
+
attributes, and in HTML `#to_html`), as DOM Parsing's algorithm and Firefox
|
|
353
380
|
have it, in HTML and XML. Nokogiri's `Attr#to_s` is the value (`"a"`) and
|
|
354
381
|
its `#to_html` the markup (`id="a"`); use `#value` for the value.
|
|
355
382
|
|
data/README.md
CHANGED
|
@@ -33,7 +33,9 @@ dependency.
|
|
|
33
33
|
differential, and property-based testing vs Nokogiri (see below).
|
|
34
34
|
* Bounded, fail-closed execution
|
|
35
35
|
* XPath evaluation is bounded by per-evaluation limits on work, memory, and recursion.
|
|
36
|
-
* HTML parsing bounds the tree depth (`max_tree_depth:`, default 400)
|
|
36
|
+
* HTML parsing bounds the tree depth (`max_tree_depth:`, default 400) and the
|
|
37
|
+
size of the document it builds against its input (`max_amplification:`,
|
|
38
|
+
default 256 times, never less than 64 MiB).
|
|
37
39
|
* Ownership and borrowing are kept explicit across layers, with owned/borrowed
|
|
38
40
|
string types and verified text at engine boundaries.
|
|
39
41
|
* Programmatic invalid input, limit violations, allocation failures, and unsupported constructs
|
|
@@ -80,6 +82,11 @@ Makiri::HTML(bytes, encoding: "euc-jp")
|
|
|
80
82
|
# max_tree_depth: raises the limit, and a negative value disables it
|
|
81
83
|
Makiri::HTML(deep_html, max_tree_depth: 2000)
|
|
82
84
|
|
|
85
|
+
# A short input cannot build an enormous document: more than 256 times the
|
|
86
|
+
# input (and 64 MiB) raises Makiri::Error; max_amplification: changes the ratio,
|
|
87
|
+
# and a negative value disables it
|
|
88
|
+
Makiri::HTML(html, max_amplification: 1024)
|
|
89
|
+
|
|
83
90
|
# Serialization
|
|
84
91
|
doc.at_css("#main").to_html # => "<div id=\"main\" ...>...</div>"
|
|
85
92
|
doc.at_css("#main").inner_html # => "\n <p class=\"lead\">Hello</p>\n..."
|
|
@@ -217,9 +224,9 @@ doc.at_css("p").instance_variable_get(:@wrapper) # => the same MyElement
|
|
|
217
224
|
```
|
|
218
225
|
|
|
219
226
|
A node created by `clone_node` or `import_node` is a new node with no state.
|
|
220
|
-
`pointer_id`
|
|
221
|
-
|
|
222
|
-
document, not across documents.
|
|
227
|
+
`pointer_id` tells the nodes of one document apart, not documents: a node of
|
|
228
|
+
another document may have the same value, an HTML node and an XML node
|
|
229
|
+
especially. So key a pointer-based cache per document, not across documents.
|
|
223
230
|
|
|
224
231
|
## Non-goals (v1.0)
|
|
225
232
|
|
|
@@ -270,7 +277,7 @@ See also [`spec/conformance/README.md`](spec/conformance/README.md).
|
|
|
270
277
|
## Requirements
|
|
271
278
|
|
|
272
279
|
* CRuby 3.3 or newer.
|
|
273
|
-
* Rust 1.
|
|
280
|
+
* Rust 1.95 or newer with `cargo` - the extension is a Rust crate. (Binary
|
|
274
281
|
gems are published for the common platforms, which need no toolchain.)
|
|
275
282
|
* libclang (clang's development library): rb-sys runs bindgen at build time and
|
|
276
283
|
reads Ruby's headers through it.
|
data/lib/makiri/3.3/makiri.so
CHANGED
|
Binary file
|
data/lib/makiri/3.4/makiri.so
CHANGED
|
Binary file
|
data/lib/makiri/4.0/makiri.so
CHANGED
|
Binary file
|
data/lib/makiri/html/document.rb
CHANGED
|
@@ -32,15 +32,25 @@ module Makiri
|
|
|
32
32
|
# ("document tree depth limit exceeded (400)"). The default is 400; a
|
|
33
33
|
# negative Integer disables the limit.
|
|
34
34
|
#
|
|
35
|
+
# +max_amplification+ bounds how large a document may grow against its
|
|
36
|
+
# input: at most that many times the input's bytes, and never less than
|
|
37
|
+
# 64 MiB. A larger one raises Makiri::Error ("document size limit
|
|
38
|
+
# exceeded"). The HTML Standard re-creates every unclosed formatting
|
|
39
|
+
# element (+<b>+, +<i>+, ...) before each character, so a short input
|
|
40
|
+
# can otherwise build a document thousands of times its size; ordinary
|
|
41
|
+
# documents build 10-50 times theirs. The default is 256; a negative
|
|
42
|
+
# Integer disables the limit.
|
|
43
|
+
#
|
|
35
44
|
# @param source [String, #read]
|
|
36
45
|
# @param max_tree_depth [Integer, nil] nil for the default
|
|
46
|
+
# @param max_amplification [Integer, nil] nil for the default
|
|
37
47
|
# @param encoding [String, Encoding, nil] the transport layer's
|
|
38
48
|
# encoding; a name neither Ruby nor the Encoding Standard knows
|
|
39
49
|
# raises ArgumentError
|
|
40
50
|
# @return [Makiri::HTML::Document]
|
|
41
|
-
def self.parse(source, max_tree_depth: nil, encoding: nil)
|
|
51
|
+
def self.parse(source, max_tree_depth: nil, max_amplification: nil, encoding: nil)
|
|
42
52
|
source = source.read if source.respond_to?(:read)
|
|
43
|
-
_parse(String(source), max_tree_depth, encoding&.to_s)
|
|
53
|
+
_parse(String(source), max_tree_depth, max_amplification, encoding&.to_s)
|
|
44
54
|
end
|
|
45
55
|
|
|
46
56
|
# An independent copy of the whole document (like Nokogiri's Document#dup):
|
data/lib/makiri/node.rb
CHANGED
|
@@ -164,8 +164,12 @@ module Makiri
|
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
# Query with CSS or XPath, auto-detecting which from the string shape.
|
|
167
|
-
# Strings that look like a location path (start with "/", "./", "..", "
|
|
168
|
-
# "
|
|
167
|
+
# Strings that look like a location path (start with "/", "./", "..", "("
|
|
168
|
+
# or "@", are "." alone, or name an axis, as "ancestor::div" does, outside
|
|
169
|
+
# a quoted string) are treated as XPath; everything else as CSS. No CSS
|
|
170
|
+
# selector starts with "." followed by "." or "/", or is "." alone; a
|
|
171
|
+
# "::" of a CSS pseudo-element ("p::before") or inside a quoted attribute
|
|
172
|
+
# value ("[title='a::b']") names no axis.
|
|
169
173
|
# @return [Makiri::NodeSet, String, Float, Boolean]
|
|
170
174
|
def search(path)
|
|
171
175
|
xpath?(path) ? xpath(path) : css(path)
|
|
@@ -195,11 +199,23 @@ module Makiri
|
|
|
195
199
|
|
|
196
200
|
private
|
|
197
201
|
|
|
202
|
+
# An XPath axis and its "::", not inside a longer name, a class or an id.
|
|
203
|
+
XPATH_AXIS = /(?<![\w.#-])(?:ancestor-or-self|ancestor|attribute|child|descendant-or-self|
|
|
204
|
+
descendant|following-sibling|following|namespace|parent|
|
|
205
|
+
preceding-sibling|preceding|self)\s*::/x
|
|
206
|
+
private_constant :XPATH_AXIS
|
|
207
|
+
|
|
208
|
+
# A quoted string, CSS's or XPath's: what it holds is no syntax.
|
|
209
|
+
QUOTED = /'[^']*'|"[^"]*"/
|
|
210
|
+
private_constant :QUOTED
|
|
211
|
+
|
|
198
212
|
# Heuristic used by {#search}: does +path+ look like an XPath location path
|
|
199
213
|
# rather than a CSS selector?
|
|
200
214
|
def xpath?(path)
|
|
201
215
|
s = path.to_s.strip
|
|
202
|
-
s.start_with?("/", "./", "
|
|
216
|
+
return true if s == "." || s.start_with?("/", "./", "..", "(", "@")
|
|
217
|
+
|
|
218
|
+
s.gsub(QUOTED, "").match?(XPATH_AXIS)
|
|
203
219
|
end
|
|
204
220
|
end
|
|
205
221
|
end
|
data/lib/makiri/node_set.rb
CHANGED
|
@@ -35,10 +35,11 @@ module Makiri
|
|
|
35
35
|
self[index]
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
# Concatenated outer HTML of every node in the set.
|
|
38
|
+
# Concatenated outer HTML of every node in the set. Keywords
|
|
39
|
+
# (+pretty:+, +encoding:+) are each node's {Node#to_html}'s.
|
|
39
40
|
# @return [String]
|
|
40
|
-
def to_html
|
|
41
|
-
map(
|
|
41
|
+
def to_html(**opts)
|
|
42
|
+
map { |node| node.to_html(**opts) }.join
|
|
42
43
|
end
|
|
43
44
|
alias to_s to_html
|
|
44
45
|
|
data/lib/makiri/version.rb
CHANGED
|
@@ -9,34 +9,8 @@ module Makiri
|
|
|
9
9
|
# After #key?, which #has_attribute? aliases.
|
|
10
10
|
ReaderAliases.define_on(self)
|
|
11
11
|
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
# and values compare as written, a type selector without a prefix
|
|
15
|
-
# matches its name in any namespace, and the context node's ancestors
|
|
16
|
-
# take part in the match while only its descendants are returned. An
|
|
17
|
-
# +ns+ hash of {prefix => uri} declares the prefixes the selector may
|
|
18
|
-
# use; its "xmlns" entry, if any, is the default namespace a bare type
|
|
19
|
-
# selector is then in.
|
|
20
|
-
#
|
|
21
|
-
# doc.css("entry") # <entry> in any namespace
|
|
22
|
-
# doc.css("a|entry", "a" => uri) # <entry> in uri
|
|
23
|
-
# doc.css("entry", "xmlns" => uri) # the same, as a default
|
|
24
|
-
#
|
|
25
|
-
# @return [Makiri::NodeSet]
|
|
26
|
-
def css(selector, ns = nil)
|
|
27
|
-
_css(selector.to_s, ns)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# First descendant matching +selector+, or nil. @return [Makiri::Node, nil]
|
|
31
|
-
def at_css(selector, ns = nil)
|
|
32
|
-
_at_css(selector.to_s, ns)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Whether this node matches +selector+ (full selector, combinators included).
|
|
36
|
-
# @return [Boolean]
|
|
37
|
-
def matches?(selector, ns = nil)
|
|
38
|
-
_css_matches(selector.to_s, ns)
|
|
39
|
-
end
|
|
12
|
+
# #css / #at_css / #matches? are native, as HTML's are, with the same
|
|
13
|
+
# arguments: what they mean over XML is in glue/xml_node/css.rs.
|
|
40
14
|
|
|
41
15
|
private
|
|
42
16
|
|
data/lib/makiri/xpath_context.rb
CHANGED
|
@@ -12,7 +12,8 @@ module Makiri
|
|
|
12
12
|
# Float, or boolean for the corresponding scalar XPath types.
|
|
13
13
|
#
|
|
14
14
|
# The bulk of the implementation lives in the extension (see
|
|
15
|
-
# ext/makiri/rust/src/glue/xpath_context.rs
|
|
15
|
+
# ext/makiri/rust/src/glue/xpath_context.rs, ext/makiri/rust/src/bridge/xpath/
|
|
16
|
+
# and ext/makiri/rust/engine/src/xpath/).
|
|
16
17
|
class XPathContext
|
|
17
18
|
# +#evaluate+ is defined in the extension and runs under the GVL (XPath
|
|
18
19
|
# never releases it), so it cannot corrupt memory under concurrency: the GVL
|
|
@@ -24,19 +25,17 @@ module Makiri
|
|
|
24
25
|
# Nokogiri-compatible name for {#register_namespace}.
|
|
25
26
|
alias register_ns register_namespace
|
|
26
27
|
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
|
|
31
|
-
bindings.each { |prefix, uri| register_namespace(prefix.to_s, uri.to_s) }
|
|
32
|
-
self
|
|
33
|
-
end
|
|
28
|
+
# +#register_namespaces(bindings)+ is defined in the extension: several
|
|
29
|
+
# prefix => URI bindings at once, read as every namespace Hash is (a
|
|
30
|
+
# +#xpath+ query's, +#css+'s). A key may be written as a declaration,
|
|
31
|
+
# "xmlns:p", which binds "p" - the form Node#namespaces returns.
|
|
34
32
|
|
|
35
|
-
# Register several name => value variable bindings at once.
|
|
36
|
-
#
|
|
33
|
+
# Register several name => value variable bindings at once. Names are not
|
|
34
|
+
# converted: each pair is read as {#register_variable} reads it.
|
|
35
|
+
# @param bindings [Hash{String, Symbol => Object}]
|
|
37
36
|
# @return [self]
|
|
38
37
|
def register_variables(bindings)
|
|
39
|
-
bindings.each { |name, value| register_variable(name
|
|
38
|
+
bindings.each { |name, value| register_variable(name, value) }
|
|
40
39
|
self
|
|
41
40
|
end
|
|
42
41
|
end
|
data/lib/makiri.rb
CHANGED
|
@@ -67,7 +67,7 @@ module Makiri
|
|
|
67
67
|
# Convenience constructor mirroring Nokogiri.
|
|
68
68
|
#
|
|
69
69
|
# @param source [String, #read] HTML source
|
|
70
|
-
# @param opts [Hash] +max_tree_depth:+, +encoding:+ - see
|
|
70
|
+
# @param opts [Hash] +max_tree_depth:+, +max_amplification:+, +encoding:+ - see
|
|
71
71
|
# {Makiri::HTML::Document.parse}
|
|
72
72
|
# @return [Makiri::HTML::Document]
|
|
73
73
|
def self.HTML(source, **opts) # rubocop:disable Naming/MethodName
|