makiri 0.15.0-aarch64-linux → 0.17.0.rc1-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 +116 -0
- data/NOKOGIRI_DIFFERENCES.md +52 -48
- data/NOTICE +7 -0
- data/README.md +9 -6
- data/lib/makiri/3.2/makiri.so +0 -0
- 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/version.rb +1 -1
- data/lib/makiri/xml/node_methods.rb +14 -30
- data/lib/makiri.rb +27 -8
- data/vendor/lexbor/LICENSE +223 -0
- data/vendor/lexbor/NOTICE +16 -0
- metadata +8 -23
- data/.github/workflows/ci.yml +0 -204
- data/.github/workflows/conformance.yml +0 -135
- data/.github/workflows/css-match.yml +0 -217
- data/.github/workflows/libfuzzer.yml +0 -116
- data/.github/workflows/release.yml +0 -273
- data/.github/workflows/security.yml +0 -305
- data/.github/workflows/valgrind.yml +0 -187
- data/.github/workflows/verify.yml +0 -71
- data/.gitmodules +0 -3
- data/Rakefile +0 -946
- data/script/api_manifest.rb +0 -173
- data/script/build_native_gem.rb +0 -53
- data/script/check_alloc_failures.rb +0 -815
- data/script/check_leaks.rb +0 -64
- data/script/check_unsafe_boundaries.rb +0 -774
- data/script/leaks_harness.rb +0 -90
- data/suppressions/ruby.supp +0 -194
- data/tools/pe_exports.rb +0 -124
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8710995de3498cde22ec02966971c541ba7ba3f2c9176be2566c93008bdcd82d
|
|
4
|
+
data.tar.gz: b6fd0ff75de338b8cab9b7c3ec74edd471ba64c17094ebcb50e3432818820172
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 173b0f7471ff9c615421b91ab848326990b8c9706c54cbc2049b216b1d71c15147b950f73a323ddb2e13a0580d7644453a61476cff46952cf4419c25233a2d95
|
|
7
|
+
data.tar.gz: 63d50aab4ee8a15570215b275a566d1dbbc1b11ad22551564cc5e790821711ea57feee4432c1bf28e18a3c1e2aa0251b6a30433df562aae7cfd84e6b580acfb8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,121 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
## [0.17.0.rc1] - 2026-10-22
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
* `Makiri::Lexbor::CSS.parse_stylesheet` returns the declarations in an
|
|
10
|
+
at-rule's block (`@font-face`, `@page`, ...) as its `:declarations`; they
|
|
11
|
+
were dropped.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
* HTML is parsed by Makiri's own Rust port of Lexbor's tokenizer and tree
|
|
16
|
+
builder, into a DOM of Makiri's own, and the CSS selector and stylesheet
|
|
17
|
+
parsers are ported too. A parsed document takes about 40% less memory.
|
|
18
|
+
* Installing from source needs Rust 1.84 or newer (and libclang), and no
|
|
19
|
+
longer CMake: the gem carries none of Lexbor's sources, only its LICENSE
|
|
20
|
+
and NOTICE.
|
|
21
|
+
* `Makiri::XML`'s `#css`, `#at_css` and `#matches?` run on the same matcher
|
|
22
|
+
as HTML's and answer as a browser's `querySelectorAll` does in an XML
|
|
23
|
+
document, 10-20x faster on compound selectors (`.item`, `ul li.item`).
|
|
24
|
+
This changes some answers:
|
|
25
|
+
* a bare type selector (`p`) matches that name in any namespace;
|
|
26
|
+
* the root element's namespace declarations are no longer picked up: a
|
|
27
|
+
prefix must be given in the ns Hash, whose `"xmlns"` entry is the
|
|
28
|
+
default namespace (on HTML too);
|
|
29
|
+
* a selector run on a node may match through ancestors outside it
|
|
30
|
+
(`node.css("body p")`); only the node's descendants are returned;
|
|
31
|
+
* `[a=v i]`, `:nth-child(... of S)`, and the form-state and link
|
|
32
|
+
pseudo-classes on XHTML elements are supported;
|
|
33
|
+
* `||` and `:current()` raise `Makiri::CSS::SyntaxError`, and an over-long
|
|
34
|
+
chain `Makiri::Error` (it was `Makiri::XPath::LimitExceeded`).
|
|
35
|
+
* HTML `css(selector, ns)` resolves namespace prefixes: `svg|path` is the SVG
|
|
36
|
+
`path`, `|p` an element in no namespace, `[x|href]` the attribute in `x`'s
|
|
37
|
+
namespace. A prefix the Hash does not bind raises
|
|
38
|
+
`Makiri::CSS::SyntaxError`; prefixes used to be ignored.
|
|
39
|
+
* HTML parsing follows the HTML Standard where Lexbor did not. This affects
|
|
40
|
+
malformed or unusual markup only: `<frameset>`, `<form>` and tables inside
|
|
41
|
+
`<template>`, `<![CDA` or `<!` at the end of the input, the adoption
|
|
42
|
+
agency, `<textarea>`, `<input type=HIDDEN>` and `<image>` in a table,
|
|
43
|
+
`<sup>` in SVG or MathML, and a repeated attribute name (the first is
|
|
44
|
+
kept). Fragment parsing (`#inner_html=`, `#outer_html=`, `Node#parse`,
|
|
45
|
+
`context:` given an element) takes the context element's quirks mode,
|
|
46
|
+
namespace and ancestor `<form>` into account, as browsers do.
|
|
47
|
+
* CSS selectors are parsed as Selectors 4 says: `:has()` inside `:has()` and
|
|
48
|
+
an invalid argument to `:has()` make the selector invalid, an empty
|
|
49
|
+
`:is()` / `:where()` is valid and matches nothing, and `#1a` is not an ID
|
|
50
|
+
selector.
|
|
51
|
+
* `parse_stylesheet` reads names and values by one rule for every property: a
|
|
52
|
+
declaration name is lower-cased unless it is a custom property, an at-rule
|
|
53
|
+
name is lower-cased, and a value is the text as written with whitespace
|
|
54
|
+
runs collapsed (`color: RED` stays `RED`; it came back as `red`).
|
|
55
|
+
`:specificity` is counted as Selectors 4 does (`:is()` / `:not()` /
|
|
56
|
+
`:has()` take their most specific argument).
|
|
57
|
+
|
|
58
|
+
### Removed
|
|
59
|
+
|
|
60
|
+
* The 10,000-`<option>` limit on a `<select>`: a select with any number of
|
|
61
|
+
options parses in linear time, as browsers parse it.
|
|
62
|
+
|
|
63
|
+
### Fixed
|
|
64
|
+
|
|
65
|
+
* `parse_stylesheet` keeps a rule such as `a:hover { ... }` inside `@media`
|
|
66
|
+
or `@supports`; it was read as a declaration, which dropped that rule and
|
|
67
|
+
every one after it in the block. A comment between a declaration's name
|
|
68
|
+
and its `:` no longer drops the declarations that follow.
|
|
69
|
+
* A namespaced type selector in the middle of a compound (`.x|a`) raises
|
|
70
|
+
`Makiri::CSS::SyntaxError`, as browsers do.
|
|
71
|
+
* `:any-link` / `:link` match only an HTML `a` or `area`, or an SVG `a`, with
|
|
72
|
+
an `href` (`<link href>` and `<map>` matched). `:read-write` /
|
|
73
|
+
`:read-only` follow the HTML Standard (a checkbox is read-only, an element
|
|
74
|
+
inside `contenteditable` is read-write), and `:empty` ignores processing
|
|
75
|
+
instructions.
|
|
76
|
+
* HTML's `:nth-child` family counts element siblings only:
|
|
77
|
+
`html:first-child` matched nothing after `<!doctype html>`.
|
|
78
|
+
* An attribute keeps the namespace it was made in: `set_attribute_ns` in the
|
|
79
|
+
element's own namespace replaces the attribute it set before instead of
|
|
80
|
+
adding a second, and an attribute removed from its element keeps its
|
|
81
|
+
`namespace_uri`.
|
|
82
|
+
* An attribute name is serialized in the case it was set (`e["viewBox"]` on
|
|
83
|
+
an element in no namespace was written lower-cased).
|
|
84
|
+
* A void element's `#inner_html` is empty even when it has children, and a
|
|
85
|
+
prefixed HTML, SVG or MathML element is written by its local name.
|
|
86
|
+
* `Node#line` of a void element fostered out of a table is its line, not nil.
|
|
87
|
+
* Many namespaces created with `create_element_ns` no longer make lookups
|
|
88
|
+
quadratic.
|
|
89
|
+
* `HTML::Document#import_node` given a document raises "cannot import a
|
|
90
|
+
document; use #dup", as `#clone_node` does.
|
|
91
|
+
|
|
92
|
+
## [0.16.0] - 2026-10-10
|
|
93
|
+
|
|
94
|
+
### Added
|
|
95
|
+
|
|
96
|
+
* `Makiri::NATIVE_VERSION` and `Makiri::NATIVE_RUBY_API_VERSION`: the gem
|
|
97
|
+
version and Ruby `MAJOR.MINOR` the native extension was built as.
|
|
98
|
+
`require "makiri"` raises `LoadError` for an extension built for another
|
|
99
|
+
Ruby (refused by the extension itself, before it defines anything) or as
|
|
100
|
+
another makiri version (e.g. a stale `lib/makiri/makiri.bundle` in a
|
|
101
|
+
checkout).
|
|
102
|
+
* `Node#child_count`, `#child_at(i)`, `#element_child_count` and
|
|
103
|
+
`#element_child_at(i)` (HTML and XML): count and index a child list without
|
|
104
|
+
building `#children`. A loop over the indexes in order costs O(1) a step,
|
|
105
|
+
also while other lists are read in between. Any child-list edit in the
|
|
106
|
+
document resets that, so a loop that edits as it indexes walks from the
|
|
107
|
+
nearer end after each edit. `child_at` returns nil for a negative index or
|
|
108
|
+
one past the end.
|
|
109
|
+
* `Node#first_child` (an alias of `#child`) and `#last_child`.
|
|
110
|
+
* `Node#root_node`, DOM `getRootNode()`: the Document, a DocumentFragment, or
|
|
111
|
+
the top of a detached subtree. An Attr is its own root.
|
|
112
|
+
|
|
113
|
+
### Changed
|
|
114
|
+
|
|
115
|
+
* `#local_name`, `#prefix`, `#namespace_uri` and `#tag_name` return frozen,
|
|
116
|
+
interned Strings: every read of one name returns the same object. `#name`
|
|
117
|
+
still returns a new, mutable String.
|
|
118
|
+
|
|
3
119
|
## [0.15.0] - 2026-10-09
|
|
4
120
|
|
|
5
121
|
### Added
|
data/NOKOGIRI_DIFFERENCES.md
CHANGED
|
@@ -149,7 +149,7 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
|
|
|
149
149
|
* `<?php ... ?>` in HTML input is a **ProcessingInstruction** node; `#to_html`
|
|
150
150
|
writes it back as `<?php ... ?>`, and `<?` at end of input is ignored.
|
|
151
151
|
* The HTML Standard added processing-instruction tokens and tree-construction
|
|
152
|
-
rules for them
|
|
152
|
+
rules for them, and Makiri's parser follows them. `Nokogiri::HTML5` (gumbo)
|
|
153
153
|
still produces the older bogus comment (`<!--?php ... ?-->`), and
|
|
154
154
|
`Nokogiri::HTML` (libxml2) its own comment.
|
|
155
155
|
|
|
@@ -158,17 +158,14 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
|
|
|
158
158
|
Nokogiri's. `inner_html=`, `outer_html=` and `Node#parse` take no keyword.
|
|
159
159
|
`Nokogiri::HTML` (libxml2) instead stops at depth 256 and returns the
|
|
160
160
|
truncated document.
|
|
161
|
-
* More than 10,000 `<option>`s in one `<select>` raise `Makiri::Error`;
|
|
162
|
-
Nokogiri has no such limit.
|
|
163
161
|
|
|
164
162
|
## HTML mutation
|
|
165
163
|
|
|
166
164
|
* There is no `Node#name=` / `#node_name=` (on HTML or XML nodes). Nokogiri
|
|
167
165
|
renames a node in place and keeps its identity; the DOM has no rename, and
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
the old one (see CHANGELOG.md).
|
|
166
|
+
an element's tag decides what it is (a `<template>` owns its contents), so a
|
|
167
|
+
node cannot change its tag. Create an element of the new name, move the
|
|
168
|
+
attributes and children, and `replace` the old one (see CHANGELOG.md).
|
|
172
169
|
* Element and attribute names follow the WHATWG DOM's rules
|
|
173
170
|
* `create_element`, `[]=` and `set_attribute_ns` raise `ArgumentError` for a
|
|
174
171
|
name the DOM refuses - one holding whitespace, `/`, `>` (or `=` for an
|
|
@@ -224,26 +221,19 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
|
|
|
224
221
|
* One exception to the DOM: an HTML attribute named `xml:lang` (in no
|
|
225
222
|
namespace) becomes the XML namespace's `xml:lang`, as the XML reader reads
|
|
226
223
|
that name, so XHTML-style HTML still writes as XML.
|
|
227
|
-
* A known gap, in Lexbor's tag table: an HTML document that already holds a
|
|
228
|
-
parsed element named with a colon (`<x:y>`, one local name) and then
|
|
229
|
-
receives, by `import_node` from another document, a prefixed element
|
|
230
|
-
written the same way (`x:y` from XML: prefix `x`, local name `y`) re-points
|
|
231
|
-
the table's entry for that spelling - the parsed element then no longer
|
|
232
|
-
matches CSS `x\:y`. Copies within one document do not touch the table.
|
|
233
224
|
* An XML element with a prefix, imported into HTML, keeps it (`h:div` in
|
|
234
225
|
XHTML has the local name `div`). Two readers then disagree, as they do in
|
|
235
|
-
browsers: CSS's `div` matches it (
|
|
236
|
-
`//div` does not (an HTML element's name test reads its qualified
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
element.
|
|
226
|
+
browsers: CSS's `div` matches it (the matcher compares the local name),
|
|
227
|
+
XPath's `//div` does not (an HTML element's name test reads its qualified
|
|
228
|
+
name). `#to_html` writes the local name (`<div>`), as the HTML standard
|
|
229
|
+
does.
|
|
240
230
|
|
|
241
231
|
## CSS
|
|
242
232
|
|
|
243
233
|
* Most jQuery/Nokogiri CSS extensions are not supported (`:gt`, `:lt`, `:eq`, `:first`, ...)
|
|
244
|
-
* Makiri
|
|
245
|
-
|
|
246
|
-
|
|
234
|
+
* Makiri's selector engine is standards-based. Use XPath
|
|
235
|
+
(`xpath("//p[contains(., 'x')]")`) or Enumerable (`css('li')[1]`) for the
|
|
236
|
+
rest.
|
|
247
237
|
Standard Level-4 selectors (`:is` / `:where` / `:has`) are supported; some of which Nokogiri rejects.
|
|
248
238
|
* There is no text-containment pseudo-class. Nokogiri's `:contains()` is
|
|
249
239
|
not supported, and neither is Lexbor's `:lexbor-contains()`: it raises
|
|
@@ -255,33 +245,45 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
|
|
|
255
245
|
selector) is supported and correct on both HTML and XML - the "type" is the
|
|
256
246
|
element's own expanded name.
|
|
257
247
|
* Nokogiri (XML and HTML5) mistranslates these to first-/only-child
|
|
258
|
-
(`//*[position()=1]` / `//*[last()=1]`), so it under-matches; Makiri
|
|
259
|
-
|
|
260
|
-
*
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
*
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
248
|
+
(`//*[position()=1]` / `//*[last()=1]`), so it under-matches; Makiri does
|
|
249
|
+
not.
|
|
250
|
+
* CSS resolves a namespace prefix against the `{prefix => uri}` Hash
|
|
251
|
+
(`css(selector, ns)`), on HTML and XML alike: `svg|path` is the SVG `path`
|
|
252
|
+
once `svg` is bound, `|path` an element in no namespace, and a prefix the
|
|
253
|
+
Hash does not bind raises `Makiri::CSS::SyntaxError`. `[x|href]` finds the
|
|
254
|
+
XLink `href` once `x` is bound to XLink. The Hash's `"xmlns"` entry is the
|
|
255
|
+
default namespace, as CSS `@namespace` without a prefix sets one: a type or
|
|
256
|
+
universal selector without a prefix is then in it.
|
|
257
|
+
* Without a default, a bare type selector matches its name in any namespace
|
|
258
|
+
(`path` finds the SVG element, `entry` an Atom entry), as a browser's
|
|
259
|
+
`querySelectorAll` does. `Nokogiri::XML` binds a bare name to the root's
|
|
260
|
+
default namespace when no Hash is given, and to no namespace once one is;
|
|
261
|
+
pass `"xmlns" => uri` (or `"xmlns" => ""`) for that reading.
|
|
262
|
+
* `Makiri::XML` does not collect the document's own declarations: a prefix
|
|
263
|
+
is declared by the Hash or not at all. `Nokogiri::XML` collects the
|
|
264
|
+
root's.
|
|
265
|
+
* A bare `*` under a default namespace is in it, as CSS has it;
|
|
266
|
+
`Nokogiri::XML` matches any element.
|
|
267
|
+
* Up to 0.16 HTML accepted the Hash and ignored every prefix, and
|
|
268
|
+
`Makiri::XML` collected the root's declarations as Nokogiri does.
|
|
273
269
|
* A selector under a node matches the way `Element#querySelectorAll` does in a
|
|
274
|
-
browser, not scoped to that node, on HTML
|
|
275
|
-
`p` inside `#c` when `#c` is itself a
|
|
276
|
-
|
|
277
|
-
`Nokogiri::HTML5` and `Nokogiri::XML` scope
|
|
278
|
-
cannot be the `div`), and so
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
* The attribute case modifiers (`[a="x" i]`, `[a="x" s]`)
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
270
|
+
browser, not scoped to that node, on HTML and XML alike:
|
|
271
|
+
`at_css("#c").css("div p")` finds a `p` inside `#c` when `#c` is itself a
|
|
272
|
+
`div`, since the selector is matched against the whole tree and only the
|
|
273
|
+
results are kept to descendants. `Nokogiri::HTML5` and `Nokogiri::XML` scope
|
|
274
|
+
the selector to the node (`#c` cannot be the `div`), and so did
|
|
275
|
+
`Makiri::XML` up to 0.16. There is no `:scope`; for a scoped match, use XPath
|
|
276
|
+
from the node (`xpath(".//div//p")`).
|
|
277
|
+
* The attribute case modifiers (`[a="x" i]`, `[a="x" s]`) are supported on
|
|
278
|
+
both representations. Nokogiri refuses both on either.
|
|
279
|
+
* The form-state and link pseudo-classes (`:checked`, `:disabled`,
|
|
280
|
+
`:enabled`, `:required`, `:optional`, `:placeholder-shown`, `:link`, ...)
|
|
281
|
+
answer on `Makiri::XML` too, for XHTML elements, as browsers do in an XML
|
|
282
|
+
document; on any other element they match nothing. `Nokogiri::XML` refuses
|
|
283
|
+
them.
|
|
284
|
+
* A selector `Makiri` cannot run (the column combinator `||`, `:current()`)
|
|
285
|
+
raises `Makiri::CSS::SyntaxError`, as a browser's `querySelectorAll` throws a
|
|
286
|
+
SyntaxError, on both representations.
|
|
285
287
|
* `#matches?` answers for a DETACHED node (`document.create_element("p")
|
|
286
288
|
.matches?("p")` is true, on both representations). Nokogiri raises
|
|
287
289
|
`NoMethodError` there - it implements `#matches?` as a search from
|
|
@@ -294,7 +296,9 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
|
|
|
294
296
|
therefore matches no type selector.
|
|
295
297
|
* `Nokogiri::HTML5` is case-sensitive on HTML elements too, so `LI` does not
|
|
296
298
|
match `<li>` there. `Makiri::XML`'s `#css` is case-sensitive, as XML names
|
|
297
|
-
are
|
|
299
|
+
are - an XHTML element's included, as in a browser's XML document - and so
|
|
300
|
+
are its attribute values, the HTML Standard's case-insensitive list of
|
|
301
|
+
attributes applying only to an HTML document.
|
|
298
302
|
|
|
299
303
|
## Serialization
|
|
300
304
|
|
data/NOTICE
CHANGED
|
@@ -8,6 +8,13 @@ This product includes software developed by:
|
|
|
8
8
|
Licensed under the Apache License, Version 2.0
|
|
9
9
|
https://lexbor.com / https://github.com/lexbor/lexbor
|
|
10
10
|
|
|
11
|
+
The HTML tokenizer and tree builder under ext/makiri/rust/src/html/ and the
|
|
12
|
+
CSS syntax, selector and stylesheet parser under
|
|
13
|
+
ext/makiri/rust/src/selectors/ are Rust ports of Lexbor's, as are the HTML
|
|
14
|
+
CSS matcher under ext/makiri/rust/src/css_match/ and the tag and
|
|
15
|
+
attribute tables generated from Lexbor's. The extension links no Lexbor
|
|
16
|
+
code; Lexbor's LICENSE and NOTICE are kept under vendor/lexbor/ in the gem.
|
|
17
|
+
|
|
11
18
|
The XPath 1.0 engine under ext/makiri/rust/src/xpath/ is an original
|
|
12
19
|
implementation written for this project. No code is derived from libxml2 or
|
|
13
20
|
libxslt.
|
data/README.md
CHANGED
|
@@ -28,8 +28,7 @@ XPath 1.0 evaluation in its own native engine, with no libxml2 dependency.
|
|
|
28
28
|
differential, and property-based testing vs Nokogiri (see below).
|
|
29
29
|
* Bounded, fail-closed execution
|
|
30
30
|
* XPath evaluation is bounded by per-evaluation limits on work, memory, and recursion.
|
|
31
|
-
* HTML parsing bounds the tree depth (`max_tree_depth:`, default 400)
|
|
32
|
-
`<option>`s per `<select>` (10,000).
|
|
31
|
+
* HTML parsing bounds the tree depth (`max_tree_depth:`, default 400).
|
|
33
32
|
* Ownership and borrowing are kept explicit across layers, with owned/borrowed
|
|
34
33
|
string types and verified text at engine boundaries.
|
|
35
34
|
* Programmatic invalid input, limit violations, allocation failures, and unsupported constructs
|
|
@@ -109,9 +108,10 @@ el = doc.at_xpath("//a:entry", ns)
|
|
|
109
108
|
el.local_name # => "entry"
|
|
110
109
|
el.namespace_uri # => "http://www.w3.org/2005/Atom"
|
|
111
110
|
|
|
112
|
-
# CSS selectors work too
|
|
113
|
-
#
|
|
111
|
+
# CSS selectors work too, as in a browser: a bare type selector matches its
|
|
112
|
+
# name in any namespace, so this just works.
|
|
114
113
|
doc.css("entry").length # => 2
|
|
114
|
+
doc.css("a|entry", ns).length # => 2 (a prefix the Hash binds)
|
|
115
115
|
doc.css("feed > entry").map { |e| e.at_css("title").text } # => ["Hello", "World"]
|
|
116
116
|
|
|
117
117
|
# Serialize back to XML
|
|
@@ -256,10 +256,13 @@ See also [`spec/conformance/README.md`](spec/conformance/README.md).
|
|
|
256
256
|
## Requirements
|
|
257
257
|
|
|
258
258
|
* CRuby 3.2 or newer.
|
|
259
|
-
*
|
|
259
|
+
* Rust 1.84 or newer with `cargo` - the extension is a Rust crate. (Binary
|
|
260
|
+
gems are published for the common platforms, which need no toolchain.)
|
|
260
261
|
* libclang (clang's development library): rb-sys runs bindgen at build time and
|
|
261
262
|
reads Ruby's headers through it.
|
|
262
|
-
|
|
263
|
+
|
|
264
|
+
Development also needs CMake and a C toolchain, to build the vendored Lexbor
|
|
265
|
+
that the Rust port is tested against (`rake lexbor`).
|
|
263
266
|
|
|
264
267
|
## Build (development)
|
|
265
268
|
|
data/lib/makiri/3.2/makiri.so
CHANGED
|
Binary file
|
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/version.rb
CHANGED
|
@@ -28,30 +28,33 @@ module Makiri
|
|
|
28
28
|
# After #key?, which #has_attribute? aliases.
|
|
29
29
|
ReaderAliases.define_on(self)
|
|
30
30
|
|
|
31
|
-
# CSS selector queries over XML,
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
31
|
+
# CSS selector queries over XML, matched by the same engine as HTML's,
|
|
32
|
+
# as a browser's querySelectorAll matches them in an XML document: names
|
|
33
|
+
# and values compare as written, a type selector without a prefix
|
|
34
|
+
# matches its name in any namespace, and the context node's ancestors
|
|
35
|
+
# take part in the match while only its descendants are returned. An
|
|
36
|
+
# +ns+ hash of {prefix => uri} declares the prefixes the selector may
|
|
37
|
+
# use; its "xmlns" entry, if any, is the default namespace a bare type
|
|
38
|
+
# selector is then in.
|
|
37
39
|
#
|
|
38
|
-
# doc.css("entry")
|
|
39
|
-
# doc.css("a|entry", "a" => uri)
|
|
40
|
+
# doc.css("entry") # <entry> in any namespace
|
|
41
|
+
# doc.css("a|entry", "a" => uri) # <entry> in uri
|
|
42
|
+
# doc.css("entry", "xmlns" => uri) # the same, as a default
|
|
40
43
|
#
|
|
41
44
|
# @return [Makiri::NodeSet]
|
|
42
45
|
def css(selector, ns = nil)
|
|
43
|
-
_css(selector.to_s,
|
|
46
|
+
_css(selector.to_s, ns)
|
|
44
47
|
end
|
|
45
48
|
|
|
46
49
|
# First descendant matching +selector+, or nil. @return [Makiri::Node, nil]
|
|
47
50
|
def at_css(selector, ns = nil)
|
|
48
|
-
_at_css(selector.to_s,
|
|
51
|
+
_at_css(selector.to_s, ns)
|
|
49
52
|
end
|
|
50
53
|
|
|
51
54
|
# Whether this node matches +selector+ (full selector, combinators included).
|
|
52
55
|
# @return [Boolean]
|
|
53
56
|
def matches?(selector, ns = nil)
|
|
54
|
-
_css_matches(selector.to_s,
|
|
57
|
+
_css_matches(selector.to_s, ns)
|
|
55
58
|
end
|
|
56
59
|
|
|
57
60
|
private
|
|
@@ -61,25 +64,6 @@ module Makiri
|
|
|
61
64
|
def unprefixed_element_namespace
|
|
62
65
|
nil
|
|
63
66
|
end
|
|
64
|
-
|
|
65
|
-
# Build the {prefix => uri} hash the native primitives register. Matching
|
|
66
|
-
# Nokogiri: with NO explicit namespaces the document's own declarations are
|
|
67
|
-
# collected (the default namespace under the synthetic prefix "xmlns", so a
|
|
68
|
-
# bare type selector binds to it - the RSS/Atom common case); but once the
|
|
69
|
-
# caller passes a namespaces hash, ONLY those prefixes are used and a bare
|
|
70
|
-
# selector resolves to no namespace (Nokogiri disables the default binding
|
|
71
|
-
# the moment an explicit map is given). Reading only the root's
|
|
72
|
-
# declarations is O(root attributes), not the whole-document walk.
|
|
73
|
-
def _css_namespaces(user)
|
|
74
|
-
return user.transform_keys(&:to_s).transform_values(&:to_s) if user && !user.empty?
|
|
75
|
-
|
|
76
|
-
reg = {}
|
|
77
|
-
root = document&.root
|
|
78
|
-
root&.namespace_definitions&.each do |ns|
|
|
79
|
-
reg[ns.prefix.nil? ? "xmlns" : ns.prefix] = ns.href
|
|
80
|
-
end
|
|
81
|
-
reg
|
|
82
|
-
end
|
|
83
67
|
end
|
|
84
68
|
end
|
|
85
69
|
end
|
data/lib/makiri.rb
CHANGED
|
@@ -2,17 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "makiri/version"
|
|
4
4
|
|
|
5
|
-
# Native extension (a Rust crate)
|
|
6
|
-
# (
|
|
7
|
-
#
|
|
8
|
-
# is
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
# Native extension (a Rust crate): lib/makiri/<major.minor>/makiri.<dlext> in a
|
|
6
|
+
# precompiled gem (one per Ruby), else lib/makiri/makiri.<dlext> (a source
|
|
7
|
+
# install, or a checkout's `rake compile`). The versioned one is required only
|
|
8
|
+
# if it is there: rescuing LoadError instead would also swallow the extension's
|
|
9
|
+
# own refusal (a binary built for another Ruby raises LoadError from its init)
|
|
10
|
+
# and load the fallback over it.
|
|
11
|
+
versioned = "makiri/#{RUBY_VERSION[/\A\d+\.\d+/]}/makiri"
|
|
12
|
+
if File.exist?(File.join(__dir__, "#{versioned}.#{RbConfig::CONFIG["DLEXT"]}"))
|
|
13
|
+
require_relative versioned
|
|
14
|
+
else
|
|
13
15
|
require_relative "makiri/makiri"
|
|
14
16
|
end
|
|
15
17
|
|
|
18
|
+
# The fallback loads lib/makiri/makiri.<dlext> whichever version of this gem's
|
|
19
|
+
# Ruby code is asking: a checkout (or a Bundler `path:` gem) keeps one binary
|
|
20
|
+
# from its last compile, and one from another gem version lacks or misnames
|
|
21
|
+
# methods. The extension states what it was built as, and a mismatch stops
|
|
22
|
+
# here; a binary older than the constant states nothing, a mismatch too. (A
|
|
23
|
+
# binary for another Ruby never gets this far: the extension refuses it
|
|
24
|
+
# before it defines anything.)
|
|
25
|
+
module Makiri
|
|
26
|
+
native_version = const_defined?(:NATIVE_VERSION, false) ? NATIVE_VERSION : "(unknown)"
|
|
27
|
+
if native_version != VERSION
|
|
28
|
+
raise LoadError,
|
|
29
|
+
"makiri's native extension was built as makiri #{native_version}, but was " \
|
|
30
|
+
"loaded by makiri #{VERSION}; rebuild it (`bundle exec rake clean compile` in a " \
|
|
31
|
+
"checkout, or reinstall the gem)"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
16
35
|
require_relative "makiri/error"
|
|
17
36
|
require_relative "makiri/clone_via_dup"
|
|
18
37
|
require_relative "makiri/xpath_syntax"
|