leptris 1.9.374.0-arm-linux → 1.9.376.0-arm-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.
@@ -203,10 +203,12 @@ int buffer_has_error(SerializeBuffer* buf) {
203
203
 
204
204
 
205
205
  /* Inline escaped-text emitter (TODO 194d): writes into a caller-
206
- * reserved worst-case buffer (6 bytes per input byte), preserving
207
- * the entity semantics of the previous per-run walkers — entity
208
- * references emit as-is (text mode), bare & escapes, quotes are
209
- * ordinary in text mode and escaped in attribute mode. */
206
+ * reserved worst-case buffer (6 bytes per input byte). Every '&' is
207
+ * escaped — entity references are parse-time markup and either
208
+ * already decoded into the text (predefined/char refs) or carried as
209
+ * ENTITY_REF nodes; a decoded text value shaped like "&" is
210
+ * data, not markup (leptris-ruby#515). Quotes are ordinary in text
211
+ * mode and escaped in attribute mode. */
210
212
  /* Escape-class table (serialize endgame): the run scan was 3-4
211
213
  * compares per byte — the dominant serializer cost at 57% of the
212
214
  * text-heavy profile. One indexed load + one test per byte, the
@@ -300,23 +302,9 @@ static char* emit_escaped_inline(char* out, const char* content,
300
302
  }
301
303
 
302
304
  if (content[i] == '&') {
303
- size_t j = i + 1;
304
- int found_semicolon = 0;
305
- while (j < len && j < i + 12) {
306
- if (content[j] == ';') { found_semicolon = 1; break; }
307
- if (!isalnum((unsigned char)content[j]) && content[j] != '#' && content[j] != '-') break;
308
- j++;
309
- }
310
- if (!attr_mode && found_semicolon && j > i + 1) {
311
- size_t n = j - i + 1;
312
- memcpy(out, &content[i], n);
313
- out += n;
314
- i = j + 1;
315
- } else {
316
- memcpy(out, "&amp;", 5);
317
- out += 5;
318
- i++;
319
- }
305
+ memcpy(out, "&amp;", 5);
306
+ out += 5;
307
+ i++;
320
308
  continue;
321
309
  }
322
310
  if (content[i] == '<') { memcpy(out, "&lt;", 4); out += 4; }
@@ -716,8 +704,8 @@ void serialize_text_internal(LeptrisTextNode* text, SerializeBuffer* buf) {
716
704
  }
717
705
 
718
706
  /* Run-batched (TODO 194b): bulk-append ordinary bytes up to the
719
- * next special character; the entity lookahead only runs at '&'.
720
- * Quotes and apostrophes are ordinary in text content. */
707
+ * next special character. Quotes and apostrophes are ordinary in
708
+ * text content. */
721
709
  size_t i = 0;
722
710
  while (i < content_len) {
723
711
  size_t run = i;
@@ -733,26 +721,10 @@ void serialize_text_internal(LeptrisTextNode* text, SerializeBuffer* buf) {
733
721
  }
734
722
 
735
723
  if (content[i] == '&') {
736
- /* Look ahead for ';' to detect entity reference */
737
- size_t j = i + 1;
738
- int found_semicolon = 0;
739
- while (j < text->content_len && j < i + 12) {
740
- if (content[j] == ';') {
741
- found_semicolon = 1;
742
- break;
743
- }
744
- if (!isalnum((unsigned char)content[j]) && content[j] != '#' && content[j] != '-') {
745
- break;
746
- }
747
- j++;
748
- }
749
- if (found_semicolon && j > i + 1) {
750
- buffer_append_len(buf, &content[i], j - i + 1);
751
- i = j + 1;
752
- } else {
753
- buffer_append_len(buf, "&amp;", 5);
754
- i++;
755
- }
724
+ /* Always escape: decoded text is data. Named references
725
+ * that survived parsing live in ENTITY_REF nodes. */
726
+ buffer_append_len(buf, "&amp;", 5);
727
+ i++;
756
728
  continue;
757
729
  }
758
730
 
@@ -977,9 +977,19 @@ TEST(Html5LibCorpus, ErrorVerdictParity) {
977
977
  for (size_t i = 0; i < failures.size() && i < 20; i++)
978
978
  printf(" VERDICT %s\n", failures[i].c_str());
979
979
  EXPECT_GT(total, (size_t)1500);
980
- /* Verdict-parity floor — set at the slice-2 baseline
981
- * (1394/1555; was 190 before the #1771 emission slices —
982
- * the doctype-less initial-mode family, trailing chars, EOF with
983
- * open elements; slice 3 adds the raw-text EOF variants). Only raises. */
984
- EXPECT_GE(parity, (size_t)1394);
980
+ /* Verdict-parity floor — main measured 1446/1555 before these
981
+ * slices (1409 was the slice-2 baseline; was 190 before the
982
+ * #1771 emission slices). Raw-text stray end tags add 12 depth-0
983
+ * cases; non-html-root adds the 9 later-<html> cases; the
984
+ * end-tag-too-early slices add heading name mismatches, block
985
+ * closes over non-implied elements, and the same rule on the
986
+ * implied close of li/dd/dt/p start tags; the after-body and
987
+ * frameset phase slices add the AfterBody/AfterFrameset/
988
+ * AfterAfter* start-tag codes; the start-tag phase slice adds
989
+ * InBody frameset, duplicate body/head, and AfterHead
990
+ * out-of-my-head tags; the select/table/foreign slice adds
991
+ * unexpected-input-in-select, hidden-input-in-table, and
992
+ * unexpected-html-element-in-foreign-content; the tokenizer
993
+ * slice adds need-space-after-doctype. Only raises. */
994
+ EXPECT_GE(parity, (size_t)1508);
985
995
  }
@@ -257,6 +257,93 @@ TEST(EncodingEdgeCases, EmptyXmlElementRoundTrips) {
257
257
  leptris_document_free(doc);
258
258
  }
259
259
 
260
+ /* leptris-ruby#514: strict load validates the input against the
261
+ * effective encoding. Without a declaration (or with a UTF-8 one)
262
+ * the entity is UTF-8 in XML 1.0; invalid byte sequences are a
263
+ * fatal load error, matching libxml2's "Invalid bytes in character
264
+ * encoding". A declared non-UTF-8 encoding is exempt — those bytes
265
+ * are legitimately not UTF-8. */
266
+ TEST(EncodingUtf8Strict, RejectsInvalidBytesWithoutDeclaration) {
267
+ const char bad[] = "<r>\xC3\x28</r>";
268
+ LeptrisStatus st = LEPTRIS_OK;
269
+ LeptrisDocument doc = leptris_parse_string(bad, sizeof(bad) - 1, &st);
270
+ EXPECT_EQ(doc, nullptr);
271
+ EXPECT_EQ(st, LEPTRIS_ERROR_PARSE);
272
+ }
273
+
274
+ TEST(EncodingUtf8Strict, RejectsInvalidBytesWithUtf8Declaration) {
275
+ const char bad[] =
276
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><r>\xC3\x28</r>";
277
+ LeptrisStatus st = LEPTRIS_OK;
278
+ LeptrisDocument doc = leptris_parse_string(bad, sizeof(bad) - 1, &st);
279
+ EXPECT_EQ(doc, nullptr);
280
+ EXPECT_EQ(st, LEPTRIS_ERROR_PARSE);
281
+
282
+ const char bad_lower[] =
283
+ "<?xml version='1.0' encoding='utf-8'?><r>\xC3\x28</r>";
284
+ LeptrisDocument doc2 = leptris_parse_string(
285
+ bad_lower, sizeof(bad_lower) - 1, &st);
286
+ EXPECT_EQ(doc2, nullptr);
287
+ }
288
+
289
+ TEST(EncodingUtf8Strict, RejectsEveryInvalidSequenceClass) {
290
+ struct { const char* xml; size_t len; } cases[] = {
291
+ {"<r>\xC0\x80</r>", 0}, /* overlong NUL */
292
+ {"<r>\xED\xA0\x80</r>", 0}, /* surrogate U+D800 */
293
+ {"<r>\xF5\x80\x80\x80</r>", 0}, /* > U+10FFFF */
294
+ {"<r>\x80</r>", 0}, /* lone continuation */
295
+ {"<r>abc\xC3", 0}, /* truncated at EOF */
296
+ {"<r a='\xC3\x28'/>", 0}, /* invalid in attribute */
297
+ };
298
+ for (auto& c : cases) {
299
+ size_t len = c.len ? c.len : std::strlen(c.xml);
300
+ LeptrisStatus st = LEPTRIS_OK;
301
+ LeptrisDocument doc = leptris_parse_string(c.xml, len, &st);
302
+ EXPECT_EQ(doc, nullptr) << "accepted invalid bytes";
303
+ if (doc) leptris_document_free(doc);
304
+ }
305
+ }
306
+
307
+ TEST(EncodingUtf8Strict, AcceptsValidMultibyte) {
308
+ const char xml[] = "<r>caf\xC3\xA9 \xE4\xB8\xAD \xF0\x9F\x98\x80</r>";
309
+ LeptrisStatus st = LEPTRIS_OK;
310
+ LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
311
+ ASSERT_NE(doc, nullptr);
312
+ EXPECT_STREQ(leptris_element_text(leptris_document_root(doc)),
313
+ "caf\xC3\xA9 \xE4\xB8\xAD \xF0\x9F\x98\x80");
314
+ leptris_document_free(doc);
315
+ }
316
+
317
+ TEST(EncodingUtf8Strict, DeclaredNonUtf8IsExempt) {
318
+ /* ISO-8859-1 0xE9 is not valid UTF-8 but is valid in the
319
+ * declared encoding: the load must not reject it. Depending on
320
+ * the iconv build it either transcodes to UTF-8 ("café") or
321
+ * passes the raw declared byte through — both are documented
322
+ * shapes (#514); only the bogus UTF-8 rejection would fail. */
323
+ const char xml[] =
324
+ "<?xml version='1.0' encoding='ISO-8859-1'?><r>caf\xE9</r>";
325
+ LeptrisStatus st = LEPTRIS_OK;
326
+ LeptrisDocument doc = leptris_parse_string(xml, sizeof(xml) - 1, &st);
327
+ ASSERT_NE(doc, nullptr);
328
+ const char* text = leptris_element_text(leptris_document_root(doc));
329
+ ASSERT_NE(text, nullptr);
330
+ EXPECT_TRUE(std::string(text) == "caf\xC3\xA9" ||
331
+ std::string(text) == "caf\xE9")
332
+ << "unexpected content byte(s)";
333
+ leptris_document_free(doc);
334
+ }
335
+
336
+ TEST(EncodingUtf8Strict, RecoverLaneKeepsBestEffortTree) {
337
+ /* #1660: RECOVER never returns NULL for malformed input; the
338
+ * encoding check must not break that contract. */
339
+ const char bad[] = "<r>\xC3\x28</r>";
340
+ LeptrisStatus st = LEPTRIS_OK;
341
+ LeptrisDocument doc = leptris_parse_string_flags(
342
+ bad, sizeof(bad) - 1, LEPTRIS_PARSE_RECOVER, &st);
343
+ ASSERT_NE(doc, nullptr);
344
+ leptris_document_free(doc);
345
+ }
346
+
260
347
  } // namespace
261
348
 
262
349
  /* Issue #613: with_encoding on declared ISO-8859-1 must deliver
@@ -39,6 +39,71 @@ TEST(SerializeRoundTrip, EscapesBareAmpersandInText) {
39
39
  leptris_document_free(doc);
40
40
  }
41
41
 
42
+ TEST(SerializeRoundTrip, EscapesEntityShapedTextUnconditionally) {
43
+ // leptris-ruby#515: parse decodes entities into text; a decoded
44
+ // text value that LOOKS like an entity reference ("&#x26;",
45
+ // "&amp;", "&lt;UK&gt;") must still escape its '&' on output.
46
+ // The old serializer passed entity-shaped runs through verbatim,
47
+ // so the next parse produced a different value (&#x41; -> A,
48
+ // &lt;UK&gt; -> a literal <UK> start tag).
49
+ struct { const char* xml; const char* want; const char* want_text; } cases[] = {
50
+ {"<r>a &amp;#x26; b</r>", "<r>a &amp;#x26; b</r>", "a &#x26; b"},
51
+ {"<r>a &amp;amp; b</r>", "<r>a &amp;amp; b</r>", "a &amp; b"},
52
+ {"<r>a &amp;lt;UK&amp;gt; b</r>", "<r>a &amp;lt;UK&amp;gt; b</r>",
53
+ "a &lt;UK&gt; b"},
54
+ {"<r>a &amp;#x41; b</r>", "<r>a &amp;#x41; b</r>", "a &#x41; b"},
55
+ // Attribute forces the non-fused text emitter; the first four
56
+ // cases take the fused <name>text</name> fast path.
57
+ {"<r k='v'>a &amp;#x26; b</r>", "<r k=\"v\">a &amp;#x26; b</r>",
58
+ "a &#x26; b"},
59
+ };
60
+ for (auto& c : cases) {
61
+ LeptrisStatus st = LEPTRIS_OK;
62
+ LeptrisDocument doc = leptris_parse_string(c.xml, std::strlen(c.xml), &st);
63
+ ASSERT_NE(doc, nullptr) << c.xml;
64
+ char* serialized = leptris_document_serialize(doc, nullptr);
65
+ ASSERT_NE(serialized, nullptr) << c.xml;
66
+ EXPECT_STREQ(serialized, c.want) << c.xml;
67
+
68
+ // The emitted bytes must reparse to the same string value.
69
+ LeptrisDocument again = leptris_parse_string(
70
+ serialized, std::strlen(serialized), &st);
71
+ ASSERT_NE(again, nullptr) << serialized;
72
+ LeptrisElement root = leptris_document_root(again);
73
+ ASSERT_NE(root, nullptr) << serialized;
74
+ const char* content = leptris_element_text(root);
75
+ ASSERT_NE(content, nullptr) << serialized;
76
+ EXPECT_STREQ(content, c.want_text) << c.xml;
77
+ if (std::string(c.xml).find("UK") != std::string::npos) {
78
+ // No <UK> element may have been minted.
79
+ EXPECT_EQ(leptris_element_first_child(root, "UK"), nullptr) << c.xml;
80
+ }
81
+
82
+ leptris_document_free(again);
83
+ leptris_free_string(serialized);
84
+ leptris_document_free(doc);
85
+ }
86
+ }
87
+
88
+ TEST(SerializeRoundTrip, KeepsEntityRefNodesUnescaped) {
89
+ // KEEP_ENTITY_REFS stores named references as ENTITY_REF nodes;
90
+ // those still serialize as &name; (they are markup, not text).
91
+ const char xml[] =
92
+ "<!DOCTYPE r [<!ENTITY foo \"x\">]><r>a &foo; b</r>";
93
+ LeptrisStatus st = LEPTRIS_OK;
94
+ LeptrisDocument doc = leptris_parse_string_flags(
95
+ xml, std::strlen(xml), LEPTRIS_PARSE_KEEP_ENTITY_REFS, &st);
96
+ ASSERT_NE(doc, nullptr);
97
+ char* serialized = leptris_document_serialize(doc, nullptr);
98
+ ASSERT_NE(serialized, nullptr);
99
+ EXPECT_NE(std::string(serialized).find("&foo;"), std::string::npos)
100
+ << serialized;
101
+ EXPECT_EQ(std::string(serialized).find("&amp;foo;"), std::string::npos)
102
+ << serialized;
103
+ leptris_free_string(serialized);
104
+ leptris_document_free(doc);
105
+ }
106
+
42
107
  TEST(SerializeRoundTrip, GrowsBufferForHugeTextContent) {
43
108
  // Regression for TODO 08: buffer_ensure_capacity must grow without
44
109
  // integer overflow or silent realloc-failure corruption.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
3
3
  "name": "leptris",
4
- "version": "1.9.374",
4
+ "version": "1.9.376",
5
5
  "description": "High-performance XML parser and XPath 1.0 engine in C (libleptris)",
6
6
  "homepage": "https://github.com/leptris/leptris",
7
7
  "license": "MIT",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.374.0
4
+ version: 1.9.376.0
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - Ribose Inc.
@@ -206,6 +206,7 @@ files:
206
206
  - vendor-src/libleptris/CONTEXT.md
207
207
  - vendor-src/libleptris/LICENSE.md
208
208
  - vendor-src/libleptris/README.adoc
209
+ - vendor-src/libleptris/TODO.SOTA.md
209
210
  - vendor-src/libleptris/TODO.assemble/README.md
210
211
  - vendor-src/libleptris/TODO.bindings/01-mutation-construction.md
211
212
  - vendor-src/libleptris/TODO.bindings/02-incremental-iterparse.md