makiri 0.16.0-aarch64-linux → 0.17.0-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 651fa28c960d1fd0099870394fc7f19bef09e328ac4851d7102ebfbf9136a6a7
4
- data.tar.gz: e84db4b38c9fbe3184b90cee36976b005521dfdca1165d10adf1c70970a36918
3
+ metadata.gz: 6105f844cdd93a9733e8fc4dfdc400320d7e6c288c60586825509efc369c96e5
4
+ data.tar.gz: 15616058654971e1e2fc175f0f8916d62dfb613e217856f33544131105674e78
5
5
  SHA512:
6
- metadata.gz: 9d9e73501a9744ecf0b16610f52cdf0f8ed17473914654b5bf719cdf3e84fd333cbe77f12305b0d0be9d52da6a9652a659c7a970e0a6e317a98edbe8b4c84b6c
7
- data.tar.gz: 11627962979c3a7649f3ce09fc4bd5b7bc019626c675263ae73bae9434ebd003b565d9726bb0e8d0d497c80c01bbebfd79c0b677e40f894dcbad1135749b7e53
6
+ metadata.gz: 4779f8a49f25ef51702012714d64436a1847609009829442890f1cfbbe05be2a892657df97c854510727cef805d3895b4b176bf77e5709b74263c310a4aa9a5d
7
+ data.tar.gz: 0ba5c5e2e3f36ce6ad8ee2cedeb312d01208c4674e603b1e38a064c8030930b677895caf34f21303dd678205f1f9e7f580c11048ba7bb8d337ccec7d35894167
data/CHANGELOG.md CHANGED
@@ -1,5 +1,299 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.17.0] - 2026-11-26
4
+
5
+ The same code as 0.17.0.rc3. What changed since 0.16.0 is in the
6
+ 0.17.0.rc1, rc2 and rc3 entries below.
7
+
8
+ ## [0.17.0.rc3] - 2026-11-08
9
+
10
+ ### Security
11
+
12
+ * An HTML parse stops with `Makiri::Error` ("document size limit
13
+ exceeded") once the document it builds passes `max_amplification:` times
14
+ its input (default 256, never less than 64 MiB), so a crafted input can no
15
+ longer build a document far larger than itself; ordinary documents build
16
+ 10-50 times theirs. The keyword is taken by `Makiri::HTML`,
17
+ `Document#fragment` and `DocumentFragment.parse`, and a negative value
18
+ lifts the limit. `inner_html=` and `outer_html=` use the default.
19
+ * A selector, an XPath expression, a name or text is checked to be UTF-8 by
20
+ Makiri itself, on its own copy of the bytes, rather than trusted on the
21
+ String's cached coderange, which another C extension could leave wrong.
22
+
23
+ ### Added
24
+
25
+ * Makiri can be used outside the main Ractor. Each Ractor parses, queries,
26
+ edits and writes its own documents, in parallel with the others: XPath,
27
+ which holds the GVL and so does not scale across threads, scales across
28
+ Ractors. A Document, a node, a NodeSet or an XPathContext cannot be
29
+ shared with, copied to or moved to another Ractor.
30
+
31
+ ### Changed
32
+
33
+ * A source install needs Rust 1.95 or newer (it was 1.84). Binary gems
34
+ need no toolchain.
35
+ * An unknown keyword is `ArgumentError` in `DocumentFragment.parse`,
36
+ `Document#fragment`, `to_html`, `inner_html`, `outer_html`, `to_xml` and
37
+ `canonicalize`, as it already was in `Makiri::HTML` and `Makiri::XML`;
38
+ a misspelt one was ignored. `#xpath`, `#at_xpath` and `XPathContext.new`
39
+ read their other keywords as namespace bindings, as before.
40
+ * HTML `to_html`, `to_s`, `outer_html` and `inner_html` take `encoding:`
41
+ naming UTF-8 (a String, a Symbol or an `Encoding`), which code written
42
+ for Nokogiri passes, and refuse any other with `ArgumentError`: HTML is
43
+ written as UTF-8 alone. `NodeSet#to_html` passes its keywords to each
44
+ node's.
45
+ * An exception message is at most 256 bytes; one quoting a longer selector,
46
+ expression or name ends in `...`.
47
+ * `XPathContext#node=`, `#register_namespace(s)` and `#register_variable(s)`
48
+ on a frozen context raise `FrozenError`.
49
+ * A namespace binding given as a keyword (`doc.xpath(expr, k => uri)`) must
50
+ have a Symbol or plain String key; a String subclass raises `TypeError`.
51
+ `XPathContext#register_namespaces` takes a Hash alone; anything else is
52
+ `TypeError`.
53
+
54
+ ### Fixed
55
+
56
+ * `Node#search` and `#at` read a string as XPath when it names an axis
57
+ (`ancestor::div`) outside a quoted string, not for any `::`: a selector
58
+ with `::` in an attribute value (`a[title='a::b']`) answered nothing, and
59
+ one with a pseudo-element (`p::before`) raised
60
+ `Makiri::XPath::SyntaxError`.
61
+ * `Makiri::XML`'s `#css`, `#at_css` and `#matches?` take a selector as
62
+ `Makiri::HTML`'s do, a `String` or a `Symbol`, anything else a
63
+ `TypeError`. They called `to_s` on it, so `nil` raised
64
+ `Makiri::CSS::SyntaxError` and `1` was the selector `"1"`.
65
+ * A fragment's String `context:` naming no built-in tag (`"my-el"`) is
66
+ `ArgumentError` in every document; `Document#fragment` took one when the
67
+ document already held such an element. `"SVG"` and `"MATH"` name the SVG
68
+ and MathML roots in any case, as an HTML tag does; only the lower-case
69
+ names did.
70
+ * Inserting a fragment one of whose children is frozen raises
71
+ `FrozenError`, as inserting a frozen node does, in HTML and XML, and
72
+ inserts nothing.
73
+ * An XML Document reports what its factories (`create_element`,
74
+ `create_text_node`, `clone_node`, ...) grow it by to the GC, as an HTML
75
+ one does, so a loop that only makes nodes is collected on memory pressure.
76
+ * An XML document that begins with a UTF-16 byte order mark and declares
77
+ `encoding="UTF-16"`, as XML 1.0 writes one, parses (UTF-32's too), and so
78
+ does `to_xml(encoding: "UTF-16")`'s output; both raised
79
+ `Makiri::XML::SyntaxError`.
80
+ * An XML document declaring `encoding="US-ASCII"` that holds a character
81
+ past ASCII raises `Makiri::XML::SyntaxError`, a UTF-8 String or a byte
82
+ order mark included; the character was read.
83
+ * XML `to_xml(encoding: "US-ASCII")` writes a character past ASCII as a
84
+ character reference, in a US-ASCII String. It wrote the UTF-8 bytes
85
+ under the US-ASCII declaration, which `Makiri::XML` then refused.
86
+ * `to_xml(encoding:)` naming an encoding other than UTF-8 raises
87
+ `Makiri::Error` when an element or attribute name, a doctype, a comment,
88
+ a CDATA section or a processing instruction holds a character the
89
+ encoding has no form for. A character reference is markup only in text
90
+ and attribute values; written elsewhere, it made a name ill-formed and
91
+ changed a comment's text.
92
+
93
+ ## [0.17.0.rc2] - 2026-10-24
94
+
95
+ ### Added
96
+
97
+ * HTML documents are decoded as browsers decode them: the HTML Standard's
98
+ encoding sniffing algorithm with the Encoding Standard's decoders. A
99
+ binary (ASCII-8BIT) or US-ASCII String is read in the encoding its byte
100
+ order mark or `<meta>` declares, or as UTF-8 when it is valid UTF-8, or
101
+ else in a detected encoding (Shift_JIS, EUC-JP, ISO-2022-JP, ...); a
102
+ `<meta>` past the first 1024 bytes re-reads the document in the encoding
103
+ it names. `Makiri::HTML(src, encoding: "shift_jis")` gives the encoding
104
+ outright - read as a String tagged with it is read, so
105
+ `encoding: Encoding::UTF_32LE` works - and `Document#encoding` returns
106
+ the one used (it was always `"UTF-8"`).
107
+
108
+ ### Changed
109
+
110
+ * Ruby 3.3 or newer is required (3.2 reached its end of life in March 2026).
111
+ * Arguments are no longer converted with `to_s` / `to_str`. A string
112
+ argument (an attribute value, text content, markup, a variable value, a
113
+ namespace URI) must be a `String`, and a name (an attribute or element
114
+ name, a namespace prefix, a selector or an XPath expression) a `String` or
115
+ a `Symbol`; anything else raises `TypeError` ("... call #to_s to convert
116
+ it"), where `node["n"] = 1` used to store `"1"`. `Makiri.HTML` /
117
+ `Makiri.XML` still read an IO and convert their source with `String()`,
118
+ and `XML::Builder` still converts with `to_s`. An index or a count
119
+ (`NodeSet#[]`, `#child_at`, `to_xml(indent:)`) must likewise be an
120
+ `Integer`; `to_int` is not called.
121
+ * A binary or US-ASCII String holding invalid UTF-8 is no longer read as
122
+ UTF-8 with U+FFFD replacements: it is sniffed, and read in the encoding a
123
+ detector guesses - which, for short text or text with little variety,
124
+ can be the wrong one. A single invalid byte is enough: UTF-8 with one
125
+ stray byte, or cut off inside a character, is read whole as a legacy
126
+ encoding (windows-1252, say), as a browser reads such a local file. Pass
127
+ `encoding:` when it is known, `"utf-8"` (or a UTF-8 String) for the old
128
+ reading.
129
+ * A String in a legacy encoding is decoded with the Encoding Standard's
130
+ decoder for it rather than Ruby's transcoder, as browsers decode it:
131
+ `ISO-8859-1` reads as windows-1252 (`\x80` is `€`), and Shift_JIS's
132
+ `0x8160` is U+301C where Ruby's `Windows-31J` made U+FF5E.
133
+ * Selectors, XPath expressions, names, attribute values and text read a
134
+ String in its own encoding, as parsing does: one that is not UTF-8,
135
+ US-ASCII or binary is converted to UTF-8 first, and refused with
136
+ `Makiri::Error` when it cannot be. Its bytes were read as UTF-8, so a
137
+ Windows-1252 `"\xC3\xA9"` was stored as `é` and a UTF-16 `"a"` as `"a\0"`.
138
+ * `Makiri::XML` reads an encoding declaration by its IANA charset name or
139
+ alias in any case (`latin1`, `csISOLatin1`), as XML 1.0 has it, and
140
+ raises `Makiri::XML::SyntaxError` for a name that is neither (`utf8`);
141
+ such a declaration was ignored, or reported as conflicting with the
142
+ String's encoding.
143
+ * `Makiri::XML` `#ancestors` returns a NodeSet, as HTML's does; it returned
144
+ an Array.
145
+ * `Node#traverse` lists the subtree once, natively, before the first node is
146
+ yielded: about five times faster on a large tree, and a block that adds or
147
+ removes nodes no longer changes which nodes are visited.
148
+
149
+ ### Removed
150
+
151
+ * XPath custom-function handlers. `Node#xpath(expr, handler)`,
152
+ `#at_xpath(expr, handler)` and `XPathContext#evaluate(expr, handler)` raise
153
+ `ArgumentError`, and a call to a function XPath 1.0 does not define is an
154
+ `XPath::SyntaxError` (it was a `Makiri::Error` when the expression was
155
+ evaluated). No Ruby code runs during an evaluation any more, so mutating a
156
+ document is never refused "while evaluating XPath over it".
157
+
158
+ ### Performance
159
+
160
+ * A node wrapper keeps its data in its own object (an embedded TypedData,
161
+ Ruby 3.3+): wrapping a node for the first time is ~25-45 ns cheaper, and
162
+ a fresh document's query or walk 10-30% faster.
163
+ * A document's indexes are built when a query first needs them, each in
164
+ one walk. An XPath that names no tag (`/html/body`) no longer builds the
165
+ tag index; the text index waits until `#text` calls have walked half the
166
+ document, so a first `doc.text` is twice as fast and a first small
167
+ `li.text` builds nothing; and the order XPath sorts by is kept with the
168
+ document, so a union over 40,000 nodes sorts in 0.7 ms instead of 13 ms.
169
+ * A NodeSet of up to eight nodes holds them in itself, with no allocation
170
+ of its own: `#children` went from ~185 to ~120 ns.
171
+ * A reader that returns a String (`#text`, `#name`, `#[]`) builds it with
172
+ no intermediate copy (`#text` ~124 -> ~112 ns), and `Document#text` joins
173
+ its text with fixed-size copies (20 KB: 9.2 -> 6.7 us).
174
+
175
+ ### Fixed
176
+
177
+ * HTML `add_previous_sibling`, `add_next_sibling` and `replace` given the
178
+ node itself leave it where it is, as the DOM does and `Makiri::XML`
179
+ already did; they raised "cannot insert a node into its own subtree".
180
+ * `Makiri::XML`'s `content=` on a DocumentFragment replaces its children,
181
+ and on a Document or a DocumentType does nothing, as the DOM's
182
+ `textContent` does and HTML already did; both raised.
183
+ * `remove` / `unlink` on an HTML Document raise "cannot remove the document
184
+ node", as on an XML one; it returned the document unchanged.
185
+ * A UTF-8 byte order mark at the start of a document is no longer kept as a
186
+ U+FEFF character in the text.
187
+ * A refused `Makiri::XML` insert of a node from another document (onto a
188
+ Text node, say) no longer leaves the copy it made in the target document,
189
+ where each refused call grew it and used up its node budget.
190
+ * XPath over HTML keeps a plain attribute of an element created in the
191
+ XMLNS namespace on `@*` and `[@name]`; it was taken for a namespace
192
+ declaration and skipped.
193
+ * XPath's `id()` with many tokens indexes the document's IDs once instead
194
+ of searching it per token: 8,000 IDs over 8,000 elements raised
195
+ `Makiri::XPath::LimitExceeded`.
196
+ * `==` / `eql?` compare the nodes' Documents as well, so nodes of two
197
+ documents can no longer compare equal after the per-document counter wraps.
198
+ * Importing an XML processing instruction whose data holds `?>` into an
199
+ HTML document raises `ArgumentError`; it reported "out of memory".
200
+ * An HTML Attr serializes to the empty string, as an XML Attr does and as
201
+ DOM Parsing and Firefox have it: `attr.to_s`, `puts attr` and `NodeSet#to_s`
202
+ over attributes raised `Makiri::Error` ("HTML serialization failed").
203
+ * Under a default namespace (the ns Hash's `"xmlns"`), a compound with no
204
+ type selector (`.x`, `[a]`) matches only that namespace's elements, as if
205
+ `*` were written (Selectors 4); it matched elements in any namespace.
206
+ * An undeclared namespace prefix inside `:is()` or `:where()` drops that
207
+ alternative alone, as browsers do: `:is(a, z|a)` matches `a` instead of
208
+ raising `Makiri::CSS::SyntaxError`.
209
+
210
+ ## [0.17.0.rc1] - 2026-10-22
211
+
212
+ ### Added
213
+
214
+ * `Makiri::Lexbor::CSS.parse_stylesheet` returns the declarations in an
215
+ at-rule's block (`@font-face`, `@page`, ...) as its `:declarations`; they
216
+ were dropped.
217
+
218
+ ### Changed
219
+
220
+ * HTML is parsed by Makiri's own Rust port of Lexbor's tokenizer and tree
221
+ builder, into a DOM of Makiri's own, and the CSS selector and stylesheet
222
+ parsers are ported too. A parsed document takes about 40% less memory.
223
+ * Installing from source needs Rust 1.84 or newer (and libclang), and no
224
+ longer CMake: the gem carries none of Lexbor's sources, only its LICENSE
225
+ and NOTICE.
226
+ * `Makiri::XML`'s `#css`, `#at_css` and `#matches?` run on the same matcher
227
+ as HTML's and answer as a browser's `querySelectorAll` does in an XML
228
+ document, 10-20x faster on compound selectors (`.item`, `ul li.item`).
229
+ This changes some answers:
230
+ * a bare type selector (`p`) matches that name in any namespace;
231
+ * the root element's namespace declarations are no longer picked up: a
232
+ prefix must be given in the ns Hash, whose `"xmlns"` entry is the
233
+ default namespace (on HTML too);
234
+ * a selector run on a node may match through ancestors outside it
235
+ (`node.css("body p")`); only the node's descendants are returned;
236
+ * `[a=v i]`, `:nth-child(... of S)`, and the form-state and link
237
+ pseudo-classes on XHTML elements are supported;
238
+ * `||` and `:current()` raise `Makiri::CSS::SyntaxError`, and an over-long
239
+ chain `Makiri::Error` (it was `Makiri::XPath::LimitExceeded`).
240
+ * HTML `css(selector, ns)` resolves namespace prefixes: `svg|path` is the SVG
241
+ `path`, `|p` an element in no namespace, `[x|href]` the attribute in `x`'s
242
+ namespace. A prefix the Hash does not bind raises
243
+ `Makiri::CSS::SyntaxError`; prefixes used to be ignored.
244
+ * HTML parsing follows the HTML Standard where Lexbor did not. This affects
245
+ malformed or unusual markup only: `<frameset>`, `<form>` and tables inside
246
+ `<template>`, `<![CDA` or `<!` at the end of the input, the adoption
247
+ agency, `<textarea>`, `<input type=HIDDEN>` and `<image>` in a table,
248
+ `<sup>` in SVG or MathML, and a repeated attribute name (the first is
249
+ kept). Fragment parsing (`#inner_html=`, `#outer_html=`, `Node#parse`,
250
+ `context:` given an element) takes the context element's quirks mode,
251
+ namespace and ancestor `<form>` into account, as browsers do.
252
+ * CSS selectors are parsed as Selectors 4 says: `:has()` inside `:has()` and
253
+ an invalid argument to `:has()` make the selector invalid, an empty
254
+ `:is()` / `:where()` is valid and matches nothing, and `#1a` is not an ID
255
+ selector.
256
+ * `parse_stylesheet` reads names and values by one rule for every property: a
257
+ declaration name is lower-cased unless it is a custom property, an at-rule
258
+ name is lower-cased, and a value is the text as written with whitespace
259
+ runs collapsed (`color: RED` stays `RED`; it came back as `red`).
260
+ `:specificity` is counted as Selectors 4 does (`:is()` / `:not()` /
261
+ `:has()` take their most specific argument).
262
+
263
+ ### Removed
264
+
265
+ * The 10,000-`<option>` limit on a `<select>`: a select with any number of
266
+ options parses in linear time, as browsers parse it.
267
+
268
+ ### Fixed
269
+
270
+ * `parse_stylesheet` keeps a rule such as `a:hover { ... }` inside `@media`
271
+ or `@supports`; it was read as a declaration, which dropped that rule and
272
+ every one after it in the block. A comment between a declaration's name
273
+ and its `:` no longer drops the declarations that follow.
274
+ * A namespaced type selector in the middle of a compound (`.x|a`) raises
275
+ `Makiri::CSS::SyntaxError`, as browsers do.
276
+ * `:any-link` / `:link` match only an HTML `a` or `area`, or an SVG `a`, with
277
+ an `href` (`<link href>` and `<map>` matched). `:read-write` /
278
+ `:read-only` follow the HTML Standard (a checkbox is read-only, an element
279
+ inside `contenteditable` is read-write), and `:empty` ignores processing
280
+ instructions.
281
+ * HTML's `:nth-child` family counts element siblings only:
282
+ `html:first-child` matched nothing after `<!doctype html>`.
283
+ * An attribute keeps the namespace it was made in: `set_attribute_ns` in the
284
+ element's own namespace replaces the attribute it set before instead of
285
+ adding a second, and an attribute removed from its element keeps its
286
+ `namespace_uri`.
287
+ * An attribute name is serialized in the case it was set (`e["viewBox"]` on
288
+ an element in no namespace was written lower-cased).
289
+ * A void element's `#inner_html` is empty even when it has children, and a
290
+ prefixed HTML, SVG or MathML element is written by its local name.
291
+ * `Node#line` of a void element fostered out of a table is its line, not nil.
292
+ * Many namespaces created with `create_element_ns` no longer make lookups
293
+ quadratic.
294
+ * `HTML::Document#import_node` given a document raises "cannot import a
295
+ document; use #dup", as `#clone_node` does.
296
+
3
297
  ## [0.16.0] - 2026-10-10
4
298
 
5
299
  ### Added
@@ -41,11 +41,45 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
41
41
  and in XPath's data model. An `xmlns` on an HTML element is an ordinary
42
42
  attribute and stays visible.
43
43
 
44
- * A `StandardError` raised by a custom-function handler becomes `Makiri::Error`
45
- ("handler raised: <message>"), with the handler's exception as its `#cause`
46
- * Nokogiri re-raises the handler's exception itself. Anything that is not a
47
- `StandardError` (`Interrupt`, `SystemExit`, Timeout's exception) and a
48
- `throw` reach the caller unchanged in both.
44
+ * Arguments are not converted
45
+ * Nokogiri calls `to_s` on an attribute value, text content or a variable
46
+ value (`node["n"] = 1`). Makiri takes a `String` for those, and a `String`
47
+ or a `Symbol` for a name; anything else is a `TypeError`. The parse
48
+ entries still take an IO or anything `String()` converts, and
49
+ `XML::Builder` converts with `to_s` as Nokogiri's does.
50
+ * An index is an `Integer`: `node_set[1.5]` and a Range with a Float end
51
+ are a `TypeError`, where Nokogiri (as `Array#[]`) truncates them.
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
+
75
+ * There are no custom XPath functions
76
+ * Nokogiri answers a function XPath does not define by calling a method of
77
+ a handler object (`xpath("my-fn(.)", handler)`). Makiri runs no Ruby while
78
+ it evaluates: a call to a function XPath 1.0 does not define is an
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`).
49
83
 
50
84
  * A number literal is read as the nearest double; libxml2's own reader is not
51
85
  correctly rounded for a literal with more digits than a double holds, so
@@ -149,7 +183,7 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
149
183
  * `<?php ... ?>` in HTML input is a **ProcessingInstruction** node; `#to_html`
150
184
  writes it back as `<?php ... ?>`, and `<?` at end of input is ignored.
151
185
  * The HTML Standard added processing-instruction tokens and tree-construction
152
- rules for them; Makiri follows them through Lexbor. `Nokogiri::HTML5` (gumbo)
186
+ rules for them, and Makiri's parser follows them. `Nokogiri::HTML5` (gumbo)
153
187
  still produces the older bogus comment (`<!--?php ... ?-->`), and
154
188
  `Nokogiri::HTML` (libxml2) its own comment.
155
189
 
@@ -158,17 +192,39 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
158
192
  Nokogiri's. `inner_html=`, `outer_html=` and `Node#parse` take no keyword.
159
193
  `Nokogiri::HTML` (libxml2) instead stops at depth 256 and returns the
160
194
  truncated document.
161
- * More than 10,000 `<option>`s in one `<select>` raise `Makiri::Error`;
162
- Nokogiri has no such limit.
195
+
196
+ * A document's bytes are decoded by the HTML Standard's **encoding sniffing
197
+ algorithm**, with the Encoding Standard's decoders, and `Document#encoding`
198
+ is the encoding they were read in (`"Shift_JIS"`, `"windows-1252"`).
199
+ * A binary (ASCII-8BIT) or US-ASCII String with no `<meta>` charset is read
200
+ as UTF-8 when it is valid UTF-8 and is otherwise detected (Shift_JIS,
201
+ EUC-JP, ISO-2022-JP, ...), as browsers read a local file. One invalid
202
+ byte - a stray one, or a character cut off at the end - rules UTF-8 out,
203
+ and the whole document is read in the detected encoding; pass
204
+ `encoding: "utf-8"` for input known to be UTF-8, and only the bad bytes
205
+ become U+FFFD. `Nokogiri::HTML5` reads it as windows-1252, so valid
206
+ UTF-8 and Shift_JIS alike come out garbled.
207
+ * A `<meta>` charset past the first 1024 bytes re-reads the document in that
208
+ encoding, as browsers do; `Nokogiri::HTML5` ignores it.
209
+ * A String with an encoding is read in that encoding, and `encoding:` gives
210
+ one explicitly; a `<meta>` cannot override either. Both use the Encoding
211
+ Standard's decoders rather than Ruby's transcoders, so `ISO-8859-1` reads
212
+ as windows-1252 (`\x80` is `€`) and Shift_JIS's `0x8160` is U+301C, as in
213
+ browsers.
214
+ * `Nokogiri::HTML5`'s `#encoding` is always `"UTF-8"`.
163
215
 
164
216
  ## HTML mutation
165
217
 
218
+ * `Node#traverse` lists the subtree before the first node is yielded
219
+ * Nokogiri reads each node's children as it reaches it, so a block that
220
+ adds a node below or after the current one can have it visited. Makiri
221
+ visits the nodes there were when `traverse` was called, in the same
222
+ order (each node after its children).
166
223
  * There is no `Node#name=` / `#node_name=` (on HTML or XML nodes). Nokogiri
167
224
  renames a node in place and keeps its identity; the DOM has no rename, and
168
- Lexbor keeps elements such as `<template>`, `<option>` and `<style>` in
169
- structs of their own, so a node cannot change its tag safely. Create an
170
- element of the new name, move the attributes and children, and `replace`
171
- the old one (see CHANGELOG.md).
225
+ an element's tag decides what it is (a `<template>` owns its contents), so a
226
+ node cannot change its tag. Create an element of the new name, move the
227
+ attributes and children, and `replace` the old one (see CHANGELOG.md).
172
228
  * Element and attribute names follow the WHATWG DOM's rules
173
229
  * `create_element`, `[]=` and `set_attribute_ns` raise `ArgumentError` for a
174
230
  name the DOM refuses - one holding whitespace, `/`, `>` (or `=` for an
@@ -193,7 +249,7 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
193
249
  not: its parsed contents live in the separate fragment `Element#content_fragment`
194
250
  returns, `template.children` is empty, and `inner_html` / `inner_html=`
195
251
  special-case the contents (the WHATWG DOM special-cases `innerHTML` alone;
196
- `append_child`, `content=`, and `children` act on the element's own empty
252
+ `add_child`, `content=`, and `children` act on the element's own empty
197
253
  children, as the specification says). Nokogiri treats `<template>` as an
198
254
  ordinary element, with the parsed nodes as its children, so
199
255
  `template.inner_html` and `template.children` answer the other way round and
@@ -224,26 +280,19 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
224
280
  * One exception to the DOM: an HTML attribute named `xml:lang` (in no
225
281
  namespace) becomes the XML namespace's `xml:lang`, as the XML reader reads
226
282
  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
283
  * An XML element with a prefix, imported into HTML, keeps it (`h:div` in
234
284
  XHTML has the local name `div`). Two readers then disagree, as they do in
235
- browsers: CSS's `div` matches it (Lexbor matches the local name), XPath's
236
- `//div` does not (an HTML element's name test reads its qualified name). And
237
- Lexbor's HTML serializer writes the prefix (`<h:div>`), where the HTML
238
- standard writes the local name, so the HTML does not re-parse to the same
239
- element.
285
+ browsers: CSS's `div` matches it (the matcher compares the local name),
286
+ XPath's `//div` does not (an HTML element's name test reads its qualified
287
+ name). `#to_html` writes the local name (`<div>`), as the HTML standard
288
+ does.
240
289
 
241
290
  ## CSS
242
291
 
243
292
  * Most jQuery/Nokogiri CSS extensions are not supported (`:gt`, `:lt`, `:eq`, `:first`, ...)
244
- * Makiri uses Lexbor's selector engine, which is standards-based apart from one
245
- text-containment extension. Use XPath (`xpath("//p[contains(., 'x')]")`) or
246
- Enumerable (`css('li')[1]`) for the rest.
293
+ * Makiri's selector engine is standards-based. Use XPath
294
+ (`xpath("//p[contains(., 'x')]")`) or Enumerable (`css('li')[1]`) for the
295
+ rest.
247
296
  Standard Level-4 selectors (`:is` / `:where` / `:has`) are supported; some of which Nokogiri rejects.
248
297
  * There is no text-containment pseudo-class. Nokogiri's `:contains()` is
249
298
  not supported, and neither is Lexbor's `:lexbor-contains()`: it raises
@@ -255,33 +304,47 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
255
304
  selector) is supported and correct on both HTML and XML - the "type" is the
256
305
  element's own expanded name.
257
306
  * Nokogiri (XML and HTML5) mistranslates these to first-/only-child
258
- (`//*[position()=1]` / `//*[last()=1]`), so it under-matches; Makiri matches
259
- Lexbor's HTML matcher.
260
- * HTML CSS takes a `{prefix => uri}` Hash (`css(selector, ns)`) but does not
261
- resolve prefixes against it: Lexbor's matcher matches a prefixed type selector
262
- loosely, so `svg|path`, `|path` and `path` all find the SVG element whatever
263
- is bound. `Nokogiri::HTML5` honours the binding (a wrong URI finds nothing).
264
- * The Hash is accepted and unused rather than refused, so the `css(selector,
265
- ns)` a caller writes for both representations works. Use `#xpath`, where a
266
- prefix IS resolved against the bindings, when the namespace matters.
267
- * `Makiri::XML` resolves CSS prefixes properly - it lowers the selector to the
268
- XPath engine, which registers the bindings.
269
- * The same holds for attribute selectors: HTML `[|href]` (no namespace) and
270
- plain `[href]` also find an SVG `xlink:href`, which `Nokogiri::HTML5`
271
- does not.
272
- `Makiri::XML` reads `[|a]` as the no-namespace attribute.
307
+ (`//*[position()=1]` / `//*[last()=1]`), so it under-matches; Makiri does
308
+ not.
309
+ * CSS resolves a namespace prefix against the `{prefix => uri}` Hash
310
+ (`css(selector, ns)`), on HTML and XML alike: `svg|path` is the SVG `path`
311
+ once `svg` is bound, `|path` an element in no namespace, and a prefix the
312
+ Hash does not bind raises `Makiri::CSS::SyntaxError`. `[x|href]` finds the
313
+ XLink `href` once `x` is bound to XLink. The Hash's `"xmlns"` entry is the
314
+ default namespace, as CSS `@namespace` without a prefix sets one: a type or
315
+ universal selector without a prefix is then in it.
316
+ * Without a default, a bare type selector matches its name in any namespace
317
+ (`path` finds the SVG element, `entry` an Atom entry), as a browser's
318
+ `querySelectorAll` does. `Nokogiri::XML` binds a bare name to the root's
319
+ default namespace when no Hash is given, and to no namespace once one is;
320
+ pass `"xmlns" => uri` (or `"xmlns" => ""`) for that reading.
321
+ * `Makiri::XML` does not collect the document's own declarations: a prefix
322
+ is declared by the Hash or not at all. `Nokogiri::XML` collects the
323
+ root's.
324
+ * A bare `*` under a default namespace is in it, as CSS has it;
325
+ `Nokogiri::XML` matches any element.
326
+ * Up to 0.16 HTML accepted the Hash and ignored every prefix, and
327
+ `Makiri::XML` collected the root's declarations as Nokogiri does.
273
328
  * A selector under a node matches the way `Element#querySelectorAll` does in a
274
- browser, not scoped to that node, on HTML: `at_css("#c").css("div p")` finds a
275
- `p` inside `#c` when `#c` is itself a `div`, since the selector is matched
276
- against the whole document and only the results are kept to descendants.
277
- `Nokogiri::HTML5` and `Nokogiri::XML` scope the selector to the node (`#c`
278
- cannot be the `div`), and so does `Makiri::XML`, which lowers the selector to
279
- an XPath from the node. Lexbor has no `:scope`; for a scoped match on HTML,
280
- use XPath from the node (`xpath(".//div//p")`).
281
- * The attribute case modifiers (`[a="x" i]`, `[a="x" s]`): HTML supports both,
282
- through Lexbor's matcher. `Makiri::XML` accepts `s` (case-sensitive, which XML
283
- values are anyway) and refuses `i` with `Makiri::CSS::SyntaxError`. Nokogiri
284
- refuses both on either representation.
329
+ browser, not scoped to that node, on HTML and XML alike:
330
+ `at_css("#c").css("div p")` finds a `p` inside `#c` when `#c` is itself a
331
+ `div`, since the selector is matched against the whole tree and only the
332
+ results are kept to descendants. `Nokogiri::HTML5` and `Nokogiri::XML` scope
333
+ the selector to the node (`#c` cannot be the `div`), and so did
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.
338
+ * The attribute case modifiers (`[a="x" i]`, `[a="x" s]`) are supported on
339
+ both representations. Nokogiri refuses both on either.
340
+ * The form-state and link pseudo-classes (`:checked`, `:disabled`,
341
+ `:enabled`, `:required`, `:optional`, `:placeholder-shown`, `:link`, ...)
342
+ answer on `Makiri::XML` too, for XHTML elements, as browsers do in an XML
343
+ document; on any other element they match nothing. `Nokogiri::XML` refuses
344
+ them.
345
+ * A selector `Makiri` cannot run (the column combinator `||`, `:current()`)
346
+ raises `Makiri::CSS::SyntaxError`, as a browser's `querySelectorAll` throws a
347
+ SyntaxError, on both representations.
285
348
  * `#matches?` answers for a DETACHED node (`document.create_element("p")
286
349
  .matches?("p")` is true, on both representations). Nokogiri raises
287
350
  `NoMethodError` there - it implements `#matches?` as a search from
@@ -294,7 +357,9 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
294
357
  therefore matches no type selector.
295
358
  * `Nokogiri::HTML5` is case-sensitive on HTML elements too, so `LI` does not
296
359
  match `<li>` there. `Makiri::XML`'s `#css` is case-sensitive, as XML names
297
- are.
360
+ are - an XHTML element's included, as in a browser's XML document - and so
361
+ are its attribute values, the HTML Standard's case-insensitive list of
362
+ attributes applying only to an HTML document.
298
363
 
299
364
  ## Serialization
300
365
 
@@ -310,6 +375,10 @@ what browsers do - rather than libxml2. Detailed, test-backed notes live in
310
375
  disabled (its children are elements, not raw text) and escaping is what makes
311
376
  that round-trip; `Nokogiri::HTML5` writes it literally and contradicts its own
312
377
  parser there.
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
380
+ have it, in HTML and XML. Nokogiri's `Attr#to_s` is the value (`"a"`) and
381
+ its `#to_html` the markup (`id="a"`); use `#value` for the value.
313
382
 
314
383
  ## Text input (mutation APIs)
315
384
 
data/NOTICE CHANGED
@@ -8,6 +8,57 @@ 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
+
18
+ * encoding_rs (linked into the native extension)
19
+ Copyright Mozilla Foundation
20
+ Licensed under the Apache License, Version 2.0 (at the licensee's option,
21
+ also the MIT license)
22
+ https://github.com/hsivonen/encoding_rs
23
+
24
+ encoding_rs includes data derived from the data files supplied with the
25
+ WHATWG Encoding Standard, under this license:
26
+
27
+ Copyright © WHATWG (Apple, Google, Mozilla, Microsoft).
28
+
29
+ Redistribution and use in source and binary forms, with or without
30
+ modification, are permitted provided that the following conditions are
31
+ met:
32
+
33
+ 1. Redistributions of source code must retain the above copyright
34
+ notice, this list of conditions and the following disclaimer.
35
+
36
+ 2. Redistributions in binary form must reproduce the above copyright
37
+ notice, this list of conditions and the following disclaimer in the
38
+ documentation and/or other materials provided with the distribution.
39
+
40
+ 3. Neither the name of the copyright holder nor the names of its
41
+ contributors may be used to endorse or promote products derived from
42
+ this software without specific prior written permission.
43
+
44
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
45
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
46
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
48
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
49
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
50
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
51
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
52
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
53
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
54
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55
+
56
+ * chardetng (linked into the native extension)
57
+ Copyright Mozilla Foundation
58
+ Licensed under the Apache License, Version 2.0 (at the licensee's option,
59
+ also the MIT license)
60
+ https://github.com/hsivonen/chardetng
61
+
11
62
  The XPath 1.0 engine under ext/makiri/rust/src/xpath/ is an original
12
63
  implementation written for this project. No code is derived from libxml2 or
13
64
  libxslt.