leptris 1.9.343.0 → 1.9.345.0
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 +34 -0
- data/Rakefile +1 -1
- data/lib/leptris/vendor/aarch64-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/aarch64-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/arm-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/arm-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/arm64-darwin/libleptris.dylib +0 -0
- data/lib/leptris/vendor/ppc64le-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/s390x-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/x86_64-darwin/libleptris.dylib +0 -0
- data/lib/leptris/vendor/x86_64-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/x86_64-linux-musl/libleptris.so +0 -0
- data/lib/leptris/version.rb +1 -1
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +68 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/src/include/leptris/types.h +13 -1
- data/vendor-src/libleptris/src/leptris/descriptor/plan.c +26 -1
- data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +106 -8
- data/vendor-src/libleptris/src/leptris/leptris.c +8 -1
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +80 -1
- data/vendor-src/libleptris/src/leptris/xsd/validate.c +20 -6
- data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +2 -0
- data/vendor-src/libleptris/test/abi/test_descriptor.cpp +32 -0
- data/vendor-src/libleptris/test/abi/test_public_surface.cpp +10 -5
- data/vendor-src/libleptris/test/parser/test_parser.cpp +74 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/ns_collision/d.xsd +12 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/ns_collision/w.xsd +11 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/ns_import_attrs/r.xsd +6 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/ns_import_attrs/w.xsd +9 -0
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +54 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d0fca7dc341727d518bedc9fa4f261d98500c3254105eed0e315574a41d1ecf
|
|
4
|
+
data.tar.gz: c00061b36680dbc8e55ca8bbaa7f143860042f0f85343f404d7a036c1d17dbf5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3aefb8147da41c686b811c1770fae59db79df8f134bfd13ca17e89a7e586440cfde6e2b59ffc00fcaeaa5e8b982f5737329d30984989a165f57e9ddd30869ad7
|
|
7
|
+
data.tar.gz: fd424edb8b6a8607f6fe46c7e6782c8c04e17141a721265d3362b9805525e7bfb7d1d42e70d7108385656c505e0d0152b971fd546207aa8127d45fc74f801ea9
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
## [1.9.345.0] - 2026-10-12
|
|
2
|
+
|
|
3
|
+
### Fixed — engine sync (libleptris 1.9.345)
|
|
4
|
+
|
|
5
|
+
- **Namespace-keyed lookups in the merged-import schema (#439,
|
|
6
|
+
#440, leptris#1663/#1665)**: the import/include merge flattened
|
|
7
|
+
declarations into one name-keyed table, and OOXML declares the
|
|
8
|
+
same names across namespaces (wml CT_TcPr vs dml, dml's
|
|
9
|
+
particles vs wml's), so validation resolved to the wrong unit's
|
|
10
|
+
declarations — hundreds of false content-model errors per real
|
|
11
|
+
document (#440's tr/tc/tcPr cascade was dml CT_TableRow
|
|
12
|
+
semantics applied to a wordprocessing table) and the r:id
|
|
13
|
+
"not declared (strict)" false positive (#439). Declarations
|
|
14
|
+
carry their declaring targetNamespace; foreign-namespace
|
|
15
|
+
fallback is forbidden once a resolving namespace is in hand.
|
|
16
|
+
Verified against the real wml.xsd: both reported documents
|
|
17
|
+
validate CLEAN. Pinned: cross-namespace same-name resolution
|
|
18
|
+
and imported-attribute (r:id) shapes.
|
|
19
|
+
|
|
20
|
+
## [1.9.344.0] - 2026-10-12
|
|
21
|
+
|
|
22
|
+
### Fixed — engine sync (libleptris 1.9.343-1.9.344)
|
|
23
|
+
|
|
24
|
+
- **recover matches XML_PARSE_RECOVER (#1660)**: structural
|
|
25
|
+
malformations commit the best-effort tree — a close tag naming
|
|
26
|
+
an open ancestor closes intermediates implicitly, a stray in-tree
|
|
27
|
+
close is dropped, unclosed elements close at EOF (pinned for
|
|
28
|
+
both shapes). Residual edge reported upstream: trailing
|
|
29
|
+
content after the root close still fails the parse
|
|
30
|
+
(comment on leptris#1660).
|
|
31
|
+
- plan_result_build SCALAR ops validate plan_index (the OOB
|
|
32
|
+
shape from the #425/#426 line) and mid-build failures no
|
|
33
|
+
longer leak the partially built tree; GCC 14 compile fix.
|
|
34
|
+
|
|
1
35
|
## [1.9.342.0] - 2026-10-12
|
|
2
36
|
|
|
3
37
|
### Fixed — engine sync (libleptris 1.9.342)
|
data/Rakefile
CHANGED
|
@@ -8,7 +8,7 @@ RSpec::Core::RakeTask.new(:spec)
|
|
|
8
8
|
# Pin for `rake compile` and the platform-gem builds. Keep in lockstep
|
|
9
9
|
# with .github/workflows/build.yml (which calls `rake compile`) and the
|
|
10
10
|
# CHANGELOG when libleptris releases.
|
|
11
|
-
LIBLEPTRIS_VERSION = "1.9.
|
|
11
|
+
LIBLEPTRIS_VERSION = "1.9.345"
|
|
12
12
|
# Vendored alongside libleptris for fn:normalize-unicode (TODO
|
|
13
13
|
# .restructure/20): built per platform with a RELOCATABLE @rpath
|
|
14
14
|
# install name, loaded by ffi.rb before libleptris so the
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/leptris/version.rb
CHANGED
data/vendor-src/README.md
CHANGED
|
@@ -1,5 +1,73 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.9.345] - 2026-10-12
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **XSD: namespace-keyed lookups in the merged-import schema
|
|
8
|
+
(leptris-ruby#440, leptris-ruby#439, PR #1665).** The
|
|
9
|
+
import/include merge flattened every unit's declarations
|
|
10
|
+
into one name-keyed table - and OOXML declares the same
|
|
11
|
+
names across namespaces (wml CT_TcPr vs dml CT_TcPr, dml's
|
|
12
|
+
global tcPr/tbl elements vs wml's local particles), so
|
|
13
|
+
validation resolved to the wrong unit's declarations:
|
|
14
|
+
hundreds of false content-model errors per real document
|
|
15
|
+
(#440's tcPr/tcW and tblBorders shapes) and the r:id
|
|
16
|
+
"not declared (strict)" false positive (#439).
|
|
17
|
+
Declarations now carry their declaring targetNamespace
|
|
18
|
+
(threaded per-file through the include/import recursion;
|
|
19
|
+
chameleon includes adopt the includer's) and every lookup
|
|
20
|
+
keys by (ns, name) - a foreign-namespace fallback is
|
|
21
|
+
forbidden once a resolving namespace is in hand. Verified
|
|
22
|
+
against the real wml.xsd: both #440 repro documents and the
|
|
23
|
+
#439 headerReference r:id document validate with 0 errors
|
|
24
|
+
(Nokogiri parity). Red-first specs with checked-in
|
|
25
|
+
ns_collision/ and ns_import_attrs/ fixtures. Full suite
|
|
26
|
+
1988/1988.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## [1.9.344] - 2026-10-12
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- **recover: structural errors keep the best-effort tree
|
|
34
|
+
(leptris#1660, PR #1661).** #547's recover mode returned an
|
|
35
|
+
EMPTY document on any parse failure - the opposite of
|
|
36
|
+
XML_PARSE_RECOVER, for exactly the malformations recovery
|
|
37
|
+
exists for. The new LEPTRIS_PARSE_RECOVER flag (which
|
|
38
|
+
leptris_parse_options.recover maps to) gives libxml2
|
|
39
|
+
semantics: a close tag naming an open ancestor closes the
|
|
40
|
+
intermediates implicitly, a stray close is dropped, and
|
|
41
|
+
elements still open at EOF close - the tree commits in every
|
|
42
|
+
case. Each recovery records a parse diagnostic (two new
|
|
43
|
+
append-only kinds: MISMATCHED_TAG, UNCLOSED_ELEMENT) through
|
|
44
|
+
the #1200 channel; without the flag parses fail exactly as
|
|
45
|
+
before. Red-first ParseRecover specs; the #547
|
|
46
|
+
empty-document contract spec superseded by
|
|
47
|
+
RecoverKeepsBestEffortTree. Full suite 1983/1983.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## [1.9.343] - 2026-10-12
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
|
|
54
|
+
- **plan_result_build: SCALAR ops validate plan_index
|
|
55
|
+
(leptris#1654, PR #1658).** The ELEMENT branch validated the
|
|
56
|
+
pool bounds; the SCALAR branch dereferenced first — an
|
|
57
|
+
out-of-pool index was an OOB read (segfault or fabricated
|
|
58
|
+
output). SCALAR now rejects with LEPTRIS_ERROR_INVALID_ARG
|
|
59
|
+
like ELEMENT. The red spec crashes on the pre-fix build; it
|
|
60
|
+
also exposed (and the PR fixes) that every mid-build failure
|
|
61
|
+
return leaked the partially built value tree — caught by
|
|
62
|
+
LSan on the Linux CI ASAN lane.
|
|
63
|
+
- **GCC 14 compile fix (leptris#1656, PR #1658).**
|
|
64
|
+
dp_mint_element passed char** attribute arrays to the
|
|
65
|
+
const char** parameters of leptris_element_new_with_attributes
|
|
66
|
+
— GCC 14 errors (all manylinux/musllinux vendored builds);
|
|
67
|
+
clang only warned. Explicit casts at the call site; the
|
|
68
|
+
-Werror compile gate was red pre-fix, clean now.
|
|
69
|
+
|
|
70
|
+
|
|
3
71
|
## [1.9.342] - 2026-10-11
|
|
4
72
|
|
|
5
73
|
### Fixed
|
|
@@ -238,7 +238,14 @@ typedef enum {
|
|
|
238
238
|
* - SKIP_SOURCE_POSITIONS: element source columns degrade to
|
|
239
239
|
* zeros (line still resolves from the buffer). */
|
|
240
240
|
LEPTRIS_PARSE_SKIP_DUP_DETECTION = 8u,
|
|
241
|
-
LEPTRIS_PARSE_SKIP_SOURCE_POSITIONS = 16u
|
|
241
|
+
LEPTRIS_PARSE_SKIP_SOURCE_POSITIONS = 16u,
|
|
242
|
+
/* XML_PARSE_RECOVER parity (leptris#1660): structural errors
|
|
243
|
+
* keep the best-effort tree — a close tag matching an open
|
|
244
|
+
* ANCESTOR closes the intermediates implicitly, a stray close
|
|
245
|
+
* is dropped, unclosed elements close at EOF. Each recovery
|
|
246
|
+
* records a parse diagnostic (mismatched-tag / unclosed-element
|
|
247
|
+
* kind). Without the bit the parse fails as before. */
|
|
248
|
+
LEPTRIS_PARSE_RECOVER = 32u
|
|
242
249
|
} LeptrisParseFlags;
|
|
243
250
|
|
|
244
251
|
/* ============================================================================
|
|
@@ -278,6 +285,11 @@ typedef enum {
|
|
|
278
285
|
* was not conformant (duplicate attribute, ...). Not a model
|
|
279
286
|
* error; SAX-lane "recover" parity (#1200). */
|
|
280
287
|
LEPTRIS_DIAG_RECOVER,
|
|
288
|
+
/* leptris#1660: structural recoveries — a close tag did not
|
|
289
|
+
* match the open element (dropped, or closed ancestors
|
|
290
|
+
* implicitly), and an element still open at EOF. Append-only. */
|
|
291
|
+
LEPTRIS_DIAG_MISMATCHED_TAG,
|
|
292
|
+
LEPTRIS_DIAG_UNCLOSED_ELEMENT,
|
|
281
293
|
LEPTRIS_DIAG_COUNT_
|
|
282
294
|
} LeptrisDiagKind;
|
|
283
295
|
|
|
@@ -1686,8 +1686,12 @@ static LeptrisElement dp_mint_element(LeptrisDocument doc,
|
|
|
1686
1686
|
? dp_join_colon(v->ns_prefix, local ? local : "")
|
|
1687
1687
|
: dp_strdup(local ? local : "");
|
|
1688
1688
|
if (!name) return NULL;
|
|
1689
|
+
/* char*[] reads as const char*[] element-wise; the DOUBLE
|
|
1690
|
+
* pointer conversion is the part C rejects (GCC 14 errors,
|
|
1691
|
+
* leptris#1656). */
|
|
1689
1692
|
LeptrisElement el = leptris_element_new_with_attributes(
|
|
1690
|
-
doc, name, v->attr_names,
|
|
1693
|
+
doc, name, (const char**)v->attr_names,
|
|
1694
|
+
(const char**)v->attr_values, v->attr_count);
|
|
1691
1695
|
free(name);
|
|
1692
1696
|
if (!el) return NULL;
|
|
1693
1697
|
const dp_plan* kids_container = &poolp->plans[v->container_plan];
|
|
@@ -1776,6 +1780,9 @@ LEPTRIS_API LeptrisPlanResult leptris_plan_result_build(
|
|
|
1776
1780
|
(op->row_index != UINT32_MAX &&
|
|
1777
1781
|
op->row_index >= pool->plans[op->plan_index]
|
|
1778
1782
|
.child_count)) {
|
|
1783
|
+
/* Mid-build failure: without this the partial
|
|
1784
|
+
* tree leaks (LSan on Linux CI catches it). */
|
|
1785
|
+
if (root) dp_result_free_rec(root);
|
|
1779
1786
|
free(stack);
|
|
1780
1787
|
if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
|
|
1781
1788
|
return NULL;
|
|
@@ -1818,6 +1825,18 @@ LEPTRIS_API LeptrisPlanResult leptris_plan_result_build(
|
|
|
1818
1825
|
stack[sp++] = v;
|
|
1819
1826
|
} else if (op->kind == LEPTRIS_PLAN_OP_SCALAR) {
|
|
1820
1827
|
if (sp == 0) {
|
|
1828
|
+
/* Mid-build failure: without this the partial
|
|
1829
|
+
* tree leaks (LSan on Linux CI catches it). */
|
|
1830
|
+
if (root) dp_result_free_rec(root);
|
|
1831
|
+
free(stack);
|
|
1832
|
+
if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
|
|
1833
|
+
return NULL;
|
|
1834
|
+
}
|
|
1835
|
+
/* The ELEMENT branch validates the pool bounds; SCALAR
|
|
1836
|
+
* reads cp->child_count right after, so an out-of-pool
|
|
1837
|
+
* plan_index here is an OOB read (leptris#1654). */
|
|
1838
|
+
if (op->plan_index >= pool->plan_count) {
|
|
1839
|
+
if (root) dp_result_free_rec(root);
|
|
1821
1840
|
free(stack);
|
|
1822
1841
|
if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
|
|
1823
1842
|
return NULL;
|
|
@@ -1839,6 +1858,9 @@ LEPTRIS_API LeptrisPlanResult leptris_plan_result_build(
|
|
|
1839
1858
|
}
|
|
1840
1859
|
} else if (op->kind == LEPTRIS_PLAN_OP_ATTR) {
|
|
1841
1860
|
if (sp == 0 || !op->name) {
|
|
1861
|
+
/* Mid-build failure: without this the partial
|
|
1862
|
+
* tree leaks (LSan on Linux CI catches it). */
|
|
1863
|
+
if (root) dp_result_free_rec(root);
|
|
1842
1864
|
free(stack);
|
|
1843
1865
|
if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
|
|
1844
1866
|
return NULL;
|
|
@@ -1875,6 +1897,9 @@ LEPTRIS_API LeptrisPlanResult leptris_plan_result_build(
|
|
|
1875
1897
|
el->attr_count++;
|
|
1876
1898
|
} else if (op->kind == LEPTRIS_PLAN_OP_END) {
|
|
1877
1899
|
if (sp == 0) {
|
|
1900
|
+
/* Mid-build failure: without this the partial
|
|
1901
|
+
* tree leaks (LSan on Linux CI catches it). */
|
|
1902
|
+
if (root) dp_result_free_rec(root);
|
|
1878
1903
|
free(stack);
|
|
1879
1904
|
if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
|
|
1880
1905
|
return NULL;
|
|
@@ -162,6 +162,9 @@ typedef struct {
|
|
|
162
162
|
* as ENTITY_REF nodes; text runs split around them. Character
|
|
163
163
|
* references (&#...;) still expand — they are not entities. */
|
|
164
164
|
int keep_entity_refs;
|
|
165
|
+
/* LEPTRIS_PARSE_RECOVER (leptris#1660): structural errors keep
|
|
166
|
+
* the best-effort tree (XML_PARSE_RECOVER semantics). */
|
|
167
|
+
int recover;
|
|
165
168
|
/* TODO 159 Phase G: parser-local last-attr cache for the element
|
|
166
169
|
* currently being parsed. Eliminates the O(N) walk-to-find-tail
|
|
167
170
|
* in dp_add_attr_inline — O(1) wiring per attr instead of O(N),
|
|
@@ -1379,7 +1382,8 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
1379
1382
|
int owns_buffer,
|
|
1380
1383
|
int drop_ws_text,
|
|
1381
1384
|
int apply_dtd_attrs,
|
|
1382
|
-
int keep_entity_refs
|
|
1385
|
+
int keep_entity_refs,
|
|
1386
|
+
int recover) {
|
|
1383
1387
|
|
|
1384
1388
|
/* 2. Create arena-backed pool (TODO 183 Phase 3).
|
|
1385
1389
|
*
|
|
@@ -1629,6 +1633,7 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
1629
1633
|
p.probe_slack = 1; /* the scratch always carries zeroed slack */
|
|
1630
1634
|
p.drop_ws_text = drop_ws_text;
|
|
1631
1635
|
p.keep_entity_refs = keep_entity_refs;
|
|
1636
|
+
p.recover = recover;
|
|
1632
1637
|
p.dtd = NULL;
|
|
1633
1638
|
/* Only ever set to 1 in the loop; without the zero here the
|
|
1634
1639
|
* field rides the stack (MSVC C4701) and doc->has_namespaces
|
|
@@ -2028,7 +2033,7 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
2028
2033
|
close_local = colon + 1;
|
|
2029
2034
|
close_local_len = close_len - (colon + 1 - close_start);
|
|
2030
2035
|
}
|
|
2031
|
-
if (open_len != close_local_len) goto
|
|
2036
|
+
if (open_len != close_local_len) goto close_mismatch;
|
|
2032
2037
|
/* Masked 64-bit compare for short names — one load
|
|
2033
2038
|
* each side vs a libc memcmp call (the TODO 174 law:
|
|
2034
2039
|
* setup dominates sub-8-byte compares; ~9% of the
|
|
@@ -2061,11 +2066,76 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
2061
2066
|
uint64_t a, b;
|
|
2062
2067
|
memcpy(&a, open_name, 8);
|
|
2063
2068
|
memcpy(&b, close_local, 8);
|
|
2064
|
-
if ((a & mask) != (b & mask)) goto
|
|
2069
|
+
if ((a & mask) != (b & mask)) goto close_mismatch;
|
|
2065
2070
|
} else if (memcmp(open_name, close_local,
|
|
2066
2071
|
close_local_len) != 0) {
|
|
2067
|
-
goto
|
|
2072
|
+
goto close_mismatch;
|
|
2073
|
+
}
|
|
2074
|
+
if (0) {
|
|
2075
|
+
close_mismatch:
|
|
2076
|
+
/* leptris#1660: RECOVER keeps the best-effort tree.
|
|
2077
|
+
* A close tag naming an open ANCESTOR closes the
|
|
2078
|
+
* intermediates implicitly (libxml2 semantics); a
|
|
2079
|
+
* close matching nothing open is dropped. Either way
|
|
2080
|
+
* the recovery records a diagnostic. */
|
|
2081
|
+
if (!p.recover) goto fail;
|
|
2082
|
+
{
|
|
2083
|
+
int anc = -1;
|
|
2084
|
+
for (int d = (int)p.depth - 1; d >= 0; d--) {
|
|
2085
|
+
LeptrisElement ae = p.open_stack[d];
|
|
2086
|
+
const char* an = elem_name(ae);
|
|
2087
|
+
size_t al = (ae->name_len != 0xFF)
|
|
2088
|
+
? (size_t)ae->name_len : strlen(an);
|
|
2089
|
+
if (al == close_local_len &&
|
|
2090
|
+
memcmp(an, close_local,
|
|
2091
|
+
close_local_len) == 0) {
|
|
2092
|
+
anc = d;
|
|
2093
|
+
break;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
if (anc >= 0) {
|
|
2097
|
+
while ((int)p.depth - 1 > anc) {
|
|
2098
|
+
LeptrisElement ce =
|
|
2099
|
+
p.open_stack[p.depth - 1];
|
|
2100
|
+
extern struct LeptrisDiag*
|
|
2101
|
+
leptris_diag_emit(
|
|
2102
|
+
struct LeptrisDiag**, int*, int*,
|
|
2103
|
+
LeptrisDiagKind, LeptrisNodeRef,
|
|
2104
|
+
const char*, ...);
|
|
2105
|
+
leptris_diag_emit(
|
|
2106
|
+
&p.doc->parse_diags,
|
|
2107
|
+
&p.doc->parse_diag_count,
|
|
2108
|
+
&p.doc->parse_diag_cap,
|
|
2109
|
+
LEPTRIS_DIAG_UNCLOSED_ELEMENT, NULL,
|
|
2110
|
+
"Element %s closed implicitly by </%.*s>",
|
|
2111
|
+
elem_name(ce),
|
|
2112
|
+
(int)close_local_len, close_local);
|
|
2113
|
+
if (p.line_offsets_ok) {
|
|
2114
|
+
leptris_elem_pos_close_at(
|
|
2115
|
+
p.doc,
|
|
2116
|
+
p.pos_slot_stack[p.depth - 1],
|
|
2117
|
+
(uint32_t)(p.pos - p.buf));
|
|
2118
|
+
}
|
|
2119
|
+
p.depth--;
|
|
2120
|
+
p.last_child_stack[p.depth] = NULL;
|
|
2121
|
+
}
|
|
2122
|
+
goto close_matched;
|
|
2123
|
+
}
|
|
2124
|
+
extern struct LeptrisDiag* leptris_diag_emit(
|
|
2125
|
+
struct LeptrisDiag**, int*, int*,
|
|
2126
|
+
LeptrisDiagKind, LeptrisNodeRef,
|
|
2127
|
+
const char*, ...);
|
|
2128
|
+
leptris_diag_emit(
|
|
2129
|
+
&p.doc->parse_diags,
|
|
2130
|
+
&p.doc->parse_diag_count,
|
|
2131
|
+
&p.doc->parse_diag_cap,
|
|
2132
|
+
LEPTRIS_DIAG_MISMATCHED_TAG, NULL,
|
|
2133
|
+
"Stray close tag </%.*s> dropped",
|
|
2134
|
+
(int)close_local_len, close_local);
|
|
2135
|
+
continue; /* p.pos is already past the '>' */
|
|
2136
|
+
}
|
|
2068
2137
|
}
|
|
2138
|
+
close_matched:
|
|
2069
2139
|
if (p.line_offsets_ok) {
|
|
2070
2140
|
/* Round 10: fill the open element's journal slot in
|
|
2071
2141
|
* place — no hash probe, and the recorded start offset
|
|
@@ -2271,7 +2341,31 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
|
|
|
2271
2341
|
}
|
|
2272
2342
|
}
|
|
2273
2343
|
|
|
2274
|
-
if (p.depth != 0)
|
|
2344
|
+
if (p.depth != 0) {
|
|
2345
|
+
if (!p.recover) goto fail;
|
|
2346
|
+
/* leptris#1660: elements still open at EOF close
|
|
2347
|
+
* implicitly; the tree commits. */
|
|
2348
|
+
while (p.depth > 0) {
|
|
2349
|
+
LeptrisElement ce = p.open_stack[p.depth - 1];
|
|
2350
|
+
extern struct LeptrisDiag* leptris_diag_emit(
|
|
2351
|
+
struct LeptrisDiag**, int*, int*,
|
|
2352
|
+
LeptrisDiagKind, LeptrisNodeRef,
|
|
2353
|
+
const char*, ...);
|
|
2354
|
+
leptris_diag_emit(
|
|
2355
|
+
&p.doc->parse_diags, &p.doc->parse_diag_count,
|
|
2356
|
+
&p.doc->parse_diag_cap,
|
|
2357
|
+
LEPTRIS_DIAG_UNCLOSED_ELEMENT, NULL,
|
|
2358
|
+
"Element %s still open at end of document",
|
|
2359
|
+
elem_name(ce));
|
|
2360
|
+
if (p.line_offsets_ok) {
|
|
2361
|
+
leptris_elem_pos_close_at(
|
|
2362
|
+
p.doc, p.pos_slot_stack[p.depth - 1],
|
|
2363
|
+
(uint32_t)(p.pos - p.buf));
|
|
2364
|
+
}
|
|
2365
|
+
p.depth--;
|
|
2366
|
+
p.last_child_stack[p.depth] = NULL;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2275
2369
|
if (!p.root) goto fail;
|
|
2276
2370
|
|
|
2277
2371
|
/* 6. Commit to doc. */
|
|
@@ -3288,14 +3382,16 @@ struct leptris_document* direct_parse(const char* xml, size_t len) {
|
|
|
3288
3382
|
struct leptris_document* d = dp_il_try(xml, len, 0, 0, 0);
|
|
3289
3383
|
if (d) return d;
|
|
3290
3384
|
}
|
|
3291
|
-
return direct_parse_internal((char*)xml, len, 0, 2, 0, 0, 0);
|
|
3385
|
+
return direct_parse_internal((char*)xml, len, 0, 2, 0, 0, 0, 0);
|
|
3292
3386
|
}
|
|
3293
3387
|
|
|
3294
3388
|
/* Public flagged entry (LEPTRIS_PARSE_DROP_WS_TEXT et al.). */
|
|
3295
3389
|
struct leptris_document* direct_parse_flags(const char* xml, size_t len,
|
|
3296
3390
|
unsigned parse_flags) {
|
|
3297
3391
|
if (!xml || len == 0) return NULL;
|
|
3298
|
-
|
|
3392
|
+
/* The interleaved lane has no recovery support (#1660) — RECOVER
|
|
3393
|
+
* parses take the default lane. */
|
|
3394
|
+
if (!(parse_flags & LEPTRIS_PARSE_RECOVER)) {
|
|
3299
3395
|
struct leptris_document* d = dp_il_try(
|
|
3300
3396
|
xml, len,
|
|
3301
3397
|
(parse_flags & LEPTRIS_PARSE_DROP_WS_TEXT) ? 1 : 0,
|
|
@@ -3312,6 +3408,8 @@ struct leptris_document* direct_parse_flags(const char* xml, size_t len,
|
|
|
3312
3408
|
(parse_flags & LEPTRIS_PARSE_DTDATTR)
|
|
3313
3409
|
? 1 : 0,
|
|
3314
3410
|
(parse_flags & LEPTRIS_PARSE_KEEP_ENTITY_REFS)
|
|
3411
|
+
? 1 : 0,
|
|
3412
|
+
(parse_flags & LEPTRIS_PARSE_RECOVER)
|
|
3315
3413
|
? 1 : 0);
|
|
3316
3414
|
}
|
|
3317
3415
|
|
|
@@ -3319,5 +3417,5 @@ struct leptris_document* direct_parse_flags(const char* xml, size_t len,
|
|
|
3319
3417
|
struct leptris_document* direct_parse_inplace(char* buf, size_t len) {
|
|
3320
3418
|
if (!buf || len == 0) return NULL;
|
|
3321
3419
|
buf[len] = '\0'; /* Ensure NUL termination */
|
|
3322
|
-
return direct_parse_internal(buf, len, 0, 0, 0, 0, 0);
|
|
3420
|
+
return direct_parse_internal(buf, len, 0, 0, 0, 0, 0, 0);
|
|
3323
3421
|
}
|
|
@@ -646,8 +646,15 @@ LEPTRIS_API LeptrisDocument leptris_parse_string_ex(const char* xml,
|
|
|
646
646
|
if (options->strict_mode >= 0) g_leptris_strict_mode = options->strict_mode;
|
|
647
647
|
if (options->max_depth > 0) g_leptris_max_depth = options->max_depth;
|
|
648
648
|
|
|
649
|
+
/* #1660: recover maps to the RECOVER parse flag — structural
|
|
650
|
+
* errors keep the best-effort tree with per-recovery parse
|
|
651
|
+
* diagnostics (leptris_document_parse_diag). The empty-document
|
|
652
|
+
* fallback below now only covers still-unrecoverable failures
|
|
653
|
+
* (e.g. encoding), preserving the #547 contract for them. */
|
|
654
|
+
unsigned flags = options->flags;
|
|
655
|
+
if (options->recover) flags |= LEPTRIS_PARSE_RECOVER;
|
|
649
656
|
LeptrisDocument doc = leptris_parse_string_flags(xml, length,
|
|
650
|
-
|
|
657
|
+
flags, status);
|
|
651
658
|
g_leptris_strict_mode = saved_strict;
|
|
652
659
|
g_leptris_max_depth = saved_depth;
|
|
653
660
|
if (!doc && options->recover) {
|
|
@@ -75,6 +75,8 @@ static XsdCm* xsd_cm_parse(struct leptris_xsd_schema* s,
|
|
|
75
75
|
static XsdAttrDecl* xsd_capture_attr_rows(struct leptris_xsd_schema* s,
|
|
76
76
|
LeptrisElement container,
|
|
77
77
|
int depth);
|
|
78
|
+
XsdCm* xsd_find_complex_ns(struct leptris_xsd_schema* s,
|
|
79
|
+
const char* type_name, const char* uri);
|
|
78
80
|
extern XsdCm* xsd_find_complex(struct leptris_xsd_schema* s,
|
|
79
81
|
const char* type_name);
|
|
80
82
|
extern const XsdTypeAttrs* xsd_find_type_attrs(
|
|
@@ -831,9 +833,18 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
|
|
|
831
833
|
strcmp(tns, s->target_ns) == 0);
|
|
832
834
|
if (subroot &&
|
|
833
835
|
(strcmp(local, "import") == 0 || same_ns)) {
|
|
836
|
+
/* leptris-ruby#440/#439: each captured
|
|
837
|
+
* unit stamps ITS OWN targetNamespace on
|
|
838
|
+
* its declarations — chameleon includes
|
|
839
|
+
* (no tns) adopt the includer's. */
|
|
840
|
+
char* saved_ns = s->target_ns;
|
|
841
|
+
char* sub_ns = tns ? xsd_strdup(tns) : NULL;
|
|
842
|
+
if (sub_ns) s->target_ns = sub_ns;
|
|
834
843
|
s->include_depth++;
|
|
835
844
|
xsd_capture_root(s, subroot);
|
|
836
845
|
s->include_depth--;
|
|
846
|
+
if (sub_ns) free(sub_ns);
|
|
847
|
+
s->target_ns = saved_ns;
|
|
837
848
|
}
|
|
838
849
|
leptris_document_free(sub);
|
|
839
850
|
}
|
|
@@ -853,6 +864,7 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
|
|
|
853
864
|
(XsdElementDecl*)calloc(1, sizeof(*d));
|
|
854
865
|
if (d) {
|
|
855
866
|
d->name = xsd_strdup(nm);
|
|
867
|
+
if (s->target_ns) d->ns = xsd_strdup(s->target_ns);
|
|
856
868
|
d->type = xsd_strdup(xsd_local_name(ty));
|
|
857
869
|
xsd_capture_alternatives(s, (LeptrisElement)n, d);
|
|
858
870
|
d->fixed = xsd_strdup(
|
|
@@ -881,6 +893,7 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
|
|
|
881
893
|
(XsdElementDecl*)calloc(1, sizeof(*d));
|
|
882
894
|
if (d) {
|
|
883
895
|
d->name = xsd_strdup(nm);
|
|
896
|
+
if (s->target_ns) d->ns = xsd_strdup(s->target_ns);
|
|
884
897
|
d->type = xsd_strdup(synth);
|
|
885
898
|
d->next = s->elements;
|
|
886
899
|
s->elements = d;
|
|
@@ -1026,6 +1039,7 @@ LEPTRIS_API void leptris_xsd_free(LeptrisXsdSchema schema) {
|
|
|
1026
1039
|
XsdTypeAttrs* ta = s->type_attrs;
|
|
1027
1040
|
while (ta) {
|
|
1028
1041
|
XsdTypeAttrs* tn = ta->next;
|
|
1042
|
+
free(ta->ns);
|
|
1029
1043
|
XsdAttrDecl* a = ta->attrs;
|
|
1030
1044
|
while (a) {
|
|
1031
1045
|
XsdAttrDecl* an = a->next;
|
|
@@ -1043,6 +1057,7 @@ LEPTRIS_API void leptris_xsd_free(LeptrisXsdSchema schema) {
|
|
|
1043
1057
|
XsdElementDecl* d = s->elements;
|
|
1044
1058
|
while (d) {
|
|
1045
1059
|
XsdElementDecl* dn = d->next;
|
|
1060
|
+
free(d->ns);
|
|
1046
1061
|
XsdAlternative* a = d->alternatives;
|
|
1047
1062
|
while (a) {
|
|
1048
1063
|
XsdAlternative* an = a->next;
|
|
@@ -1141,12 +1156,18 @@ static void xsd_register_complex(struct leptris_xsd_schema* s,
|
|
|
1141
1156
|
char* any_attr_ns) {
|
|
1142
1157
|
if (!root) return;
|
|
1143
1158
|
root->name = xsd_strdup(name);
|
|
1159
|
+
/* leptris-ruby#440: the DECLARING file's targetNamespace — the
|
|
1160
|
+
* merged-import schema is flat, so same-name types from
|
|
1161
|
+
* different namespaces (wml CT_TcPr vs dml CT_TcPr) resolve by
|
|
1162
|
+
* (ns, name). */
|
|
1163
|
+
if (s->target_ns) root->ns = xsd_strdup(s->target_ns);
|
|
1144
1164
|
root->next = s->complex_types;
|
|
1145
1165
|
s->complex_types = root;
|
|
1146
1166
|
if (attrs || any_attr_ns) {
|
|
1147
1167
|
XsdTypeAttrs* ta = (XsdTypeAttrs*)calloc(1, sizeof(*ta));
|
|
1148
1168
|
if (ta) {
|
|
1149
1169
|
ta->type_name = xsd_strdup(name);
|
|
1170
|
+
if (root->ns) ta->ns = xsd_strdup(root->ns);
|
|
1150
1171
|
ta->attrs = attrs;
|
|
1151
1172
|
ta->any_attr_ns = any_attr_ns;
|
|
1152
1173
|
ta->next = s->type_attrs;
|
|
@@ -1282,7 +1303,7 @@ static XsdCm* xsd_capture_complex_model(struct leptris_xsd_schema* s,
|
|
|
1282
1303
|
const char* base = xsd_local_name(base_raw);
|
|
1283
1304
|
XsdCm* base_root =
|
|
1284
1305
|
(base && strncmp(base, "xs:", 3) != 0)
|
|
1285
|
-
?
|
|
1306
|
+
? xsd_find_complex_ns(s, base, s->target_ns)
|
|
1286
1307
|
: NULL;
|
|
1287
1308
|
if (strcmp(dl, "extension") == 0) {
|
|
1288
1309
|
/* base content first, derived content after */
|
|
@@ -1814,6 +1835,23 @@ const XsdElementDecl* xsd_find_element(struct leptris_xsd_schema* s,
|
|
|
1814
1835
|
return NULL;
|
|
1815
1836
|
}
|
|
1816
1837
|
|
|
1838
|
+
/* leptris-ruby#440: prefer (ns, name); fall back to any match. */
|
|
1839
|
+
const XsdElementDecl* xsd_find_element_ns(
|
|
1840
|
+
struct leptris_xsd_schema* s, const char* name, const char* uri) {
|
|
1841
|
+
if (!s || !name) return NULL;
|
|
1842
|
+
if (uri && uri[0]) {
|
|
1843
|
+
for (XsdElementDecl* d = s->elements; d; d = d->next)
|
|
1844
|
+
if (d->ns && strcmp(d->name, name) == 0 &&
|
|
1845
|
+
strcmp(d->ns, uri) == 0)
|
|
1846
|
+
return d;
|
|
1847
|
+
for (XsdElementDecl* d = s->elements; d; d = d->next)
|
|
1848
|
+
if (!d->ns && strcmp(d->name, name) == 0)
|
|
1849
|
+
return d;
|
|
1850
|
+
return NULL;
|
|
1851
|
+
}
|
|
1852
|
+
return xsd_find_element(s, name);
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1817
1855
|
XsdCm* xsd_find_complex(struct leptris_xsd_schema* s,
|
|
1818
1856
|
const char* type_name) {
|
|
1819
1857
|
if (!s || !type_name) return NULL;
|
|
@@ -1822,6 +1860,30 @@ XsdCm* xsd_find_complex(struct leptris_xsd_schema* s,
|
|
|
1822
1860
|
return NULL;
|
|
1823
1861
|
}
|
|
1824
1862
|
|
|
1863
|
+
/* leptris-ruby#440: prefer the (ns, name) exact match — the flat
|
|
1864
|
+
* merged list carries same-name types from every imported
|
|
1865
|
+
* namespace. Falls back to name-only (single-namespace schemas
|
|
1866
|
+
* and unresolvable contexts keep working). */
|
|
1867
|
+
XsdCm* xsd_find_complex_ns(struct leptris_xsd_schema* s,
|
|
1868
|
+
const char* type_name, const char* uri) {
|
|
1869
|
+
if (!s || !type_name) return NULL;
|
|
1870
|
+
if (uri && uri[0]) {
|
|
1871
|
+
for (XsdCm* c = s->complex_types; c; c = c->next)
|
|
1872
|
+
if (c->ns && strcmp(c->name, type_name) == 0 &&
|
|
1873
|
+
strcmp(c->ns, uri) == 0)
|
|
1874
|
+
return c;
|
|
1875
|
+
/* A resolving namespace is in hand: a DIFFERENT
|
|
1876
|
+
* namespace's same-name decl must NOT win (wml CT_TcPr vs
|
|
1877
|
+
* dml CT_TcPr — leptris-ruby#440). Only an unstamped
|
|
1878
|
+
* (unknown-ns) entry may serve as the fallback. */
|
|
1879
|
+
for (XsdCm* c = s->complex_types; c; c = c->next)
|
|
1880
|
+
if (!c->ns && strcmp(c->name, type_name) == 0)
|
|
1881
|
+
return c;
|
|
1882
|
+
return NULL;
|
|
1883
|
+
}
|
|
1884
|
+
return xsd_find_complex(s, type_name);
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1825
1887
|
const XsdSimple* xsd_find_simple_pub(struct leptris_xsd_schema* s,
|
|
1826
1888
|
const char* name) {
|
|
1827
1889
|
return xsd_find_simple(s, name);
|
|
@@ -1839,6 +1901,23 @@ const XsdTypeAttrs* xsd_find_type_attrs(struct leptris_xsd_schema* s,
|
|
|
1839
1901
|
return NULL;
|
|
1840
1902
|
}
|
|
1841
1903
|
|
|
1904
|
+
const XsdTypeAttrs* xsd_find_type_attrs_ns(
|
|
1905
|
+
struct leptris_xsd_schema* s, const char* type_name,
|
|
1906
|
+
const char* uri) {
|
|
1907
|
+
if (!s || !type_name) return NULL;
|
|
1908
|
+
if (uri && uri[0]) {
|
|
1909
|
+
for (XsdTypeAttrs* t = s->type_attrs; t; t = t->next)
|
|
1910
|
+
if (t->ns && strcmp(t->type_name, type_name) == 0 &&
|
|
1911
|
+
strcmp(t->ns, uri) == 0)
|
|
1912
|
+
return t;
|
|
1913
|
+
for (XsdTypeAttrs* t = s->type_attrs; t; t = t->next)
|
|
1914
|
+
if (!t->ns && strcmp(t->type_name, type_name) == 0)
|
|
1915
|
+
return t;
|
|
1916
|
+
return NULL;
|
|
1917
|
+
}
|
|
1918
|
+
return xsd_find_type_attrs(s, type_name);
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1842
1921
|
/* ---- slice 4: instance validation (validate.c engine) ------------ */
|
|
1843
1922
|
|
|
1844
1923
|
LEPTRIS_API int leptris_xsd_validate(LeptrisXsdSchema schema,
|
|
@@ -33,13 +33,18 @@ struct leptris_xsd_schema; /* opaque here; compile.c owns the struct */
|
|
|
33
33
|
|
|
34
34
|
/* The validator reaches the compiled model through accessors the
|
|
35
35
|
* compiler exports (compile.c defines the struct). */
|
|
36
|
+
extern const XsdElementDecl* xsd_find_element_ns(
|
|
37
|
+
struct leptris_xsd_schema* s, const char* name, const char* uri);
|
|
36
38
|
extern const XsdElementDecl* xsd_find_element(
|
|
37
39
|
struct leptris_xsd_schema* s, const char* name);
|
|
38
|
-
extern XsdCm*
|
|
39
|
-
|
|
40
|
+
extern XsdCm* xsd_find_complex_ns(struct leptris_xsd_schema* s,
|
|
41
|
+
const char* type_name, const char* uri);
|
|
42
|
+
XsdCm* xsd_find_complex(struct leptris_xsd_schema* s, const char* type_name);
|
|
40
43
|
extern const XsdSimple* xsd_find_simple_pub(
|
|
41
44
|
struct leptris_xsd_schema* s, const char* name);
|
|
42
45
|
extern const char* xsd_target_ns(struct leptris_xsd_schema* s);
|
|
46
|
+
extern const XsdTypeAttrs* xsd_find_type_attrs_ns(
|
|
47
|
+
struct leptris_xsd_schema* s, const char* name, const char* uri);
|
|
43
48
|
extern const XsdTypeAttrs* xsd_find_type_attrs(
|
|
44
49
|
struct leptris_xsd_schema* s, const char* type_name);
|
|
45
50
|
extern const XsdElementIcs* xsd_find_element_ics(
|
|
@@ -309,7 +314,7 @@ static void validate_children(struct xsd_validator* v,
|
|
|
309
314
|
const char* cl = NULL, *cp = NULL, *cu = NULL;
|
|
310
315
|
leptris_element_expanded_name(ce, &cl, &cp, &cu);
|
|
311
316
|
if (!cl) continue;
|
|
312
|
-
if (
|
|
317
|
+
if (xsd_find_element_ns(s, cl, cu)) {
|
|
313
318
|
validate_element(v, s, ce, 0);
|
|
314
319
|
continue;
|
|
315
320
|
}
|
|
@@ -466,7 +471,9 @@ static void validate_element(struct xsd_validator* v,
|
|
|
466
471
|
const char* local = NULL, *prefix = NULL, *uri = NULL;
|
|
467
472
|
leptris_element_expanded_name(elem, &local, &prefix, &uri);
|
|
468
473
|
if (!local) return;
|
|
469
|
-
const
|
|
474
|
+
const char* guri = NULL;
|
|
475
|
+
leptris_element_expanded_name(elem, NULL, NULL, &guri);
|
|
476
|
+
const XsdElementDecl* d = xsd_find_element_ns(s, local, guri);
|
|
470
477
|
if (!d) {
|
|
471
478
|
/* strict: the instance uses an element the schema never
|
|
472
479
|
* declared (a local particle would have typed it) */
|
|
@@ -510,9 +517,16 @@ static void validate_local(struct xsd_validator* v,
|
|
|
510
517
|
LeptrisElement elem, const char* local,
|
|
511
518
|
const char* type) {
|
|
512
519
|
if (!type) return;
|
|
513
|
-
|
|
520
|
+
/* leptris-ruby#440: resolve the type in the ELEMENT's
|
|
521
|
+
* namespace — the merged-import schema carries same-name types
|
|
522
|
+
* from every imported namespace. */
|
|
523
|
+
const char* euri = NULL;
|
|
524
|
+
leptris_element_expanded_name(elem, NULL, NULL, &euri);
|
|
525
|
+
XsdCm* ct = xsd_find_complex_ns(s, type, euri);
|
|
514
526
|
if (ct) {
|
|
515
|
-
validate_attributes(
|
|
527
|
+
validate_attributes(
|
|
528
|
+
v, s, elem,
|
|
529
|
+
xsd_find_type_attrs_ns(s, type, euri));
|
|
516
530
|
validate_children(v, s, elem, ct);
|
|
517
531
|
/* XSD 1.1: the type's xs:assert list — context is the
|
|
518
532
|
* element; evaluation errors are failures */
|
|
@@ -138,6 +138,7 @@ typedef struct xsd_alternative {
|
|
|
138
138
|
/* A top-level xs:element declaration (slice 3: name + type ref). */
|
|
139
139
|
typedef struct xsd_element_decl {
|
|
140
140
|
char* name;
|
|
141
|
+
char* ns; /* leptris-ruby#440: declaring schema's targetNamespace */
|
|
141
142
|
char* type; /* "xs:string"-style builtin or a local type name */
|
|
142
143
|
XsdAlternative* alternatives; /* XSD 1.1 conditional types */
|
|
143
144
|
char* fixed; /* fixed element content: text must string-equal it */
|
|
@@ -190,6 +191,7 @@ typedef struct xsd_attrgroup_def {
|
|
|
190
191
|
|
|
191
192
|
typedef struct xsd_type_attrs {
|
|
192
193
|
char* type_name;
|
|
194
|
+
char* ns; /* leptris-ruby#440: declaring schema's tns */
|
|
193
195
|
char* any_attr_ns; /* xs:anyAttribute grammar (NULL = absent) */
|
|
194
196
|
XsdAttrDecl* attrs;
|
|
195
197
|
struct xsd_type_attrs* next;
|
|
@@ -2351,4 +2351,36 @@ TEST(Plan426, FromPlanResultMintsNativeDocument) {
|
|
|
2351
2351
|
leptris_document_free(doc);
|
|
2352
2352
|
}
|
|
2353
2353
|
|
|
2354
|
+
TEST(PlanBuild, ScalarOpRejectsOutOfPoolPlanIndex) {
|
|
2355
|
+
/* leptris#1654: SCALAR ops read pool->plans[plan_index] before
|
|
2356
|
+
* any bounds check — an out-of-pool index OOB-reads (crash or
|
|
2357
|
+
* fabricated output). Must fail with INVALID_ARG exactly like
|
|
2358
|
+
* the ELEMENT branch. */
|
|
2359
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
2360
|
+
leptris_child_plan kids[1] = {};
|
|
2361
|
+
kids[0].wire_name = "i";
|
|
2362
|
+
kids[0].kind = LEPTRIS_PLAN_KIND_COLLECTION;
|
|
2363
|
+
leptris_element_plan plans[1] = {};
|
|
2364
|
+
plans[0].element_name = "r";
|
|
2365
|
+
plans[0].child_count = 1;
|
|
2366
|
+
plans[0].child_plans = kids;
|
|
2367
|
+
leptris_plan_spec spec = {};
|
|
2368
|
+
spec.abi_version = leptris_plan_abi_version();
|
|
2369
|
+
spec.plan_count = 1;
|
|
2370
|
+
spec.plans = plans;
|
|
2371
|
+
LeptrisPlan plan = leptris_plan_build(&spec, &st);
|
|
2372
|
+
ASSERT_NE(plan, nullptr);
|
|
2373
|
+
|
|
2374
|
+
leptris_plan_row_op ops[] = {
|
|
2375
|
+
{LEPTRIS_PLAN_OP_ELEMENT, 0, UINT32_MAX, NULL, NULL, 0},
|
|
2376
|
+
{LEPTRIS_PLAN_OP_SCALAR, 9, 0, NULL, "x", 1},
|
|
2377
|
+
{LEPTRIS_PLAN_OP_END, 0, 0, NULL, NULL, 0},
|
|
2378
|
+
};
|
|
2379
|
+
LeptrisPlanResult r = leptris_plan_result_build(plan, ops, 3, &st);
|
|
2380
|
+
EXPECT_EQ(r, nullptr);
|
|
2381
|
+
EXPECT_EQ(st, LEPTRIS_ERROR_INVALID_ARG);
|
|
2382
|
+
|
|
2383
|
+
leptris_plan_free(plan);
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2354
2386
|
} // namespace
|
|
@@ -393,7 +393,11 @@ TEST(PublicSurface, RootlessWithPIsIsNotDropped) {
|
|
|
393
393
|
/* Issue #547: ParseOptions.recover returns an empty document
|
|
394
394
|
* instead of NULL on parse failure (moxml's libxml2 adapter does
|
|
395
395
|
* the same; this makes the native API honest about it). */
|
|
396
|
-
TEST(PublicSurface,
|
|
396
|
+
TEST(PublicSurface, RecoverKeepsBestEffortTree) {
|
|
397
|
+
/* leptris#1660 (supersedes the #547 empty-document contract):
|
|
398
|
+
* recover keeps the best-effort tree for structural errors —
|
|
399
|
+
* unclosed elements close at EOF, each recovery records a
|
|
400
|
+
* diagnostic. */
|
|
397
401
|
LeptrisParseOptions opts = {LEPTRIS_PARSE_DEFAULT, 0, 0, 0};
|
|
398
402
|
opts.recover = 1;
|
|
399
403
|
LeptrisStatus st = LEPTRIS_OK;
|
|
@@ -403,10 +407,11 @@ TEST(PublicSurface, RecoverReturnsEmptyDocument) {
|
|
|
403
407
|
memset(bad, 0, sizeof(bad));
|
|
404
408
|
memcpy(bad, "<root><unclosed>", 16);
|
|
405
409
|
LeptrisDocument d = leptris_parse_string_ex(bad, 16, &opts, &st);
|
|
406
|
-
ASSERT_NE(d, nullptr);
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
+
ASSERT_NE(d, nullptr);
|
|
411
|
+
LeptrisElement root = leptris_document_root(d);
|
|
412
|
+
ASSERT_NE(root, nullptr);
|
|
413
|
+
EXPECT_STREQ(leptris_element_name(root), "root");
|
|
414
|
+
EXPECT_GE(leptris_document_parse_diag_count(d), 1u);
|
|
410
415
|
leptris_document_free(d);
|
|
411
416
|
}
|
|
412
417
|
|
|
@@ -776,3 +776,77 @@ TEST(ParseDoctype, SecondDoctypeKeepsFirstModel) {
|
|
|
776
776
|
EXPECT_STREQ(text, "first");
|
|
777
777
|
leptris_document_free(d);
|
|
778
778
|
}
|
|
779
|
+
|
|
780
|
+
/* leptris#1660: XML_PARSE_RECOVER parity — structural errors keep
|
|
781
|
+
* the best-effort tree instead of an empty document. Mismatched
|
|
782
|
+
* close: an ancestor match closes the intermediates implicitly; a
|
|
783
|
+
* true stray close is dropped. Unclosed at EOF: everything open
|
|
784
|
+
* closes. Each recovery records a diagnostic; without the flag the
|
|
785
|
+
* parse still fails. */
|
|
786
|
+
TEST(ParseRecover, MismatchedCloseKeepsTreeAndDropsStray) {
|
|
787
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
788
|
+
const char xml[] = "<root><a>x</b></root>";
|
|
789
|
+
LeptrisDocument doc = leptris_parse_string_flags(
|
|
790
|
+
xml, strlen(xml), LEPTRIS_PARSE_RECOVER, &st);
|
|
791
|
+
ASSERT_NE(doc, nullptr) << "status " << (int)st;
|
|
792
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
793
|
+
ASSERT_NE(root, nullptr);
|
|
794
|
+
EXPECT_STREQ(leptris_element_name(root), "root");
|
|
795
|
+
LeptrisElement a = leptris_element_first_child_any(root);
|
|
796
|
+
ASSERT_NE(a, nullptr);
|
|
797
|
+
EXPECT_STREQ(leptris_element_name(a), "a");
|
|
798
|
+
ASSERT_NE(leptris_element_text(a), nullptr);
|
|
799
|
+
EXPECT_STREQ(leptris_element_text(a), "x");
|
|
800
|
+
/* Two recoveries: the stray </b> drops, and <a> closes
|
|
801
|
+
* implicitly when </root> names the ancestor (libxml2 reports
|
|
802
|
+
* both as well). */
|
|
803
|
+
EXPECT_EQ(leptris_document_parse_diag_count(doc), 2u);
|
|
804
|
+
leptris_document_free(doc);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
TEST(ParseRecover, MismatchedCloseForAncestorClosesIntermediates) {
|
|
808
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
809
|
+
const char xml[] = "<root><a>x</root>";
|
|
810
|
+
LeptrisDocument doc = leptris_parse_string_flags(
|
|
811
|
+
xml, strlen(xml), LEPTRIS_PARSE_RECOVER, &st);
|
|
812
|
+
ASSERT_NE(doc, nullptr) << "status " << (int)st;
|
|
813
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
814
|
+
ASSERT_NE(root, nullptr);
|
|
815
|
+
EXPECT_STREQ(leptris_element_name(root), "root");
|
|
816
|
+
LeptrisElement a = leptris_element_first_child_any(root);
|
|
817
|
+
ASSERT_NE(a, nullptr);
|
|
818
|
+
EXPECT_STREQ(leptris_element_name(a), "a");
|
|
819
|
+
ASSERT_NE(leptris_element_text(a), nullptr);
|
|
820
|
+
EXPECT_STREQ(leptris_element_text(a), "x");
|
|
821
|
+
leptris_document_free(doc);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
TEST(ParseRecover, UnclosedAtEofClosesEverything) {
|
|
825
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
826
|
+
const char xml[] = "<root><a>x";
|
|
827
|
+
LeptrisDocument doc = leptris_parse_string_flags(
|
|
828
|
+
xml, strlen(xml), LEPTRIS_PARSE_RECOVER, &st);
|
|
829
|
+
ASSERT_NE(doc, nullptr) << "status " << (int)st;
|
|
830
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
831
|
+
ASSERT_NE(root, nullptr);
|
|
832
|
+
EXPECT_STREQ(leptris_element_name(root), "root");
|
|
833
|
+
LeptrisElement a = leptris_element_first_child_any(root);
|
|
834
|
+
ASSERT_NE(a, nullptr);
|
|
835
|
+
EXPECT_STREQ(leptris_element_name(a), "a");
|
|
836
|
+
/* Both open elements (root and a) closed implicitly. */
|
|
837
|
+
EXPECT_EQ(leptris_document_parse_diag_count(doc), 2u);
|
|
838
|
+
leptris_document_free(doc);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
TEST(ParseRecover, WithoutFlagStillFails) {
|
|
842
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
843
|
+
const char xml[] = "<root><a>x</b></root>";
|
|
844
|
+
LeptrisDocument doc = leptris_parse_string_flags(
|
|
845
|
+
xml, strlen(xml), LEPTRIS_PARSE_DEFAULT, &st);
|
|
846
|
+
EXPECT_EQ(doc, nullptr);
|
|
847
|
+
EXPECT_EQ(st, LEPTRIS_ERROR_PARSE);
|
|
848
|
+
const char unclosed[] = "<root><a>x";
|
|
849
|
+
doc = leptris_parse_string_flags(unclosed, strlen(unclosed),
|
|
850
|
+
LEPTRIS_PARSE_DEFAULT, &st);
|
|
851
|
+
EXPECT_EQ(doc, nullptr);
|
|
852
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
2
|
+
targetNamespace="urn:d">
|
|
3
|
+
<!-- Same type/element NAMES as w.xsd, different namespace: the
|
|
4
|
+
merged-import compiler must resolve by (ns, name). -->
|
|
5
|
+
<xs:complexType name="CT_T">
|
|
6
|
+
<xs:sequence>
|
|
7
|
+
<xs:element name="dOnly1" minOccurs="0"/>
|
|
8
|
+
<xs:element name="dOnly2" minOccurs="0"/>
|
|
9
|
+
</xs:sequence>
|
|
10
|
+
</xs:complexType>
|
|
11
|
+
<xs:element name="r" type="CT_T"/>
|
|
12
|
+
</xs:schema>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
2
|
+
xmlns:d="urn:d" targetNamespace="urn:w">
|
|
3
|
+
<xs:import namespace="urn:d" schemaLocation="d.xsd"/>
|
|
4
|
+
<xs:complexType name="CT_T">
|
|
5
|
+
<xs:sequence>
|
|
6
|
+
<xs:element name="wOnly" minOccurs="0"/>
|
|
7
|
+
<xs:element name="tcPr" minOccurs="0"/>
|
|
8
|
+
</xs:sequence>
|
|
9
|
+
</xs:complexType>
|
|
10
|
+
<xs:element name="r" type="CT_T"/>
|
|
11
|
+
</xs:schema>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
2
|
+
xmlns:r="urn:r" targetNamespace="urn:w">
|
|
3
|
+
<xs:import namespace="urn:r" schemaLocation="r.xsd"/>
|
|
4
|
+
<xs:complexType name="CT_Ref">
|
|
5
|
+
<xs:attribute ref="r:id" use="optional"/>
|
|
6
|
+
<xs:attribute name="kind" type="xs:string" use="required"/>
|
|
7
|
+
</xs:complexType>
|
|
8
|
+
<xs:element name="ref" type="CT_Ref"/>
|
|
9
|
+
</xs:schema>
|
|
@@ -167,6 +167,60 @@ TEST(XsdCompile, ImportDagCapturesEachUnitOnce) {
|
|
|
167
167
|
leptris_xsd_free(s);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
// leptris-ruby#440/#439: the merged-import schema is FLAT, so
|
|
171
|
+
// same-name declarations from different namespaces collide. Every
|
|
172
|
+
// lookup must key by (declaring targetNamespace, name) — a
|
|
173
|
+
// resolving namespace in hand forbids a foreign-namespace fallback
|
|
174
|
+
// (wml's CT_TcPr vs dml's, dml's global tcPr element hijacking
|
|
175
|
+
// wml's local particle, r:id resolved through the import).
|
|
176
|
+
TEST(XsdCompile, SameNameTypesAcrossImportsResolveByNamespace) {
|
|
177
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
178
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(
|
|
179
|
+
LEPTRIS_XSD_CASES_DIR "/ns_collision/w.xsd", &st);
|
|
180
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0) << "status " << (int)st;
|
|
181
|
+
const char doc[] =
|
|
182
|
+
"<w:r xmlns:w=\"urn:w\"><w:tcPr/></w:r>";
|
|
183
|
+
LeptrisDocument d = leptris_parse_string(doc, strlen(doc), &st);
|
|
184
|
+
ASSERT_NE(d, nullptr);
|
|
185
|
+
// w's CT_T carries tcPr; d's same-name CT_T carries dOnly1/2 —
|
|
186
|
+
// a cross-namespace mis-resolution rejects this document.
|
|
187
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 1);
|
|
188
|
+
leptris_document_free(d);
|
|
189
|
+
// The d-namespace element resolves against d's model.
|
|
190
|
+
const char ddoc[] = "<d:r xmlns:d=\"urn:d\"><d:dOnly1/></d:r>";
|
|
191
|
+
LeptrisDocument dd = leptris_parse_string(ddoc, strlen(ddoc), &st);
|
|
192
|
+
ASSERT_NE(dd, nullptr);
|
|
193
|
+
EXPECT_EQ(leptris_xsd_validate(s, dd), 1);
|
|
194
|
+
leptris_document_free(dd);
|
|
195
|
+
leptris_xsd_free(s);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
TEST(XsdCompile, QualifiedAttrFromImportedNamespaceValidates) {
|
|
199
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
200
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(
|
|
201
|
+
LEPTRIS_XSD_CASES_DIR "/ns_import_attrs/w.xsd", &st);
|
|
202
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0) << "status " << (int)st;
|
|
203
|
+
// r:id resolved through the import; kind required by w's own
|
|
204
|
+
// attribute row.
|
|
205
|
+
const char doc[] =
|
|
206
|
+
"<w:ref xmlns:w=\"urn:w\" xmlns:r=\"urn:r\""
|
|
207
|
+
" r:id=\"rId6\" kind=\"even\"/>";
|
|
208
|
+
LeptrisDocument d = leptris_parse_string(doc, strlen(doc), &st);
|
|
209
|
+
ASSERT_NE(d, nullptr);
|
|
210
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 1);
|
|
211
|
+
leptris_document_free(d);
|
|
212
|
+
// Negative control: an undeclared qualified attribute still
|
|
213
|
+
// fails strict.
|
|
214
|
+
const char bad[] =
|
|
215
|
+
"<w:ref xmlns:w=\"urn:w\" xmlns:r=\"urn:r\""
|
|
216
|
+
" r:undeclared=\"x\" kind=\"even\"/>";
|
|
217
|
+
LeptrisDocument b = leptris_parse_string(bad, strlen(bad), &st);
|
|
218
|
+
ASSERT_NE(b, nullptr);
|
|
219
|
+
EXPECT_EQ(leptris_xsd_validate(s, b), 0);
|
|
220
|
+
leptris_document_free(b);
|
|
221
|
+
leptris_xsd_free(s);
|
|
222
|
+
}
|
|
223
|
+
|
|
170
224
|
// leptris-ruby#434: the length family counts OCTETS for binary
|
|
171
225
|
// bases (XML Schema Part 2: hexBinary/base64Binary length is in
|
|
172
226
|
// bytes) — the wml ST_LongHexNumber shape (hexBinary + length 4)
|
|
@@ -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.
|
|
4
|
+
"version": "1.9.345",
|
|
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.
|
|
4
|
+
version: 1.9.345.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -1392,6 +1392,10 @@ files:
|
|
|
1392
1392
|
- vendor-src/libleptris/test/xsd/libxml2-cases/ns1_0.xsd
|
|
1393
1393
|
- vendor-src/libleptris/test/xsd/libxml2-cases/ns2_0.xml
|
|
1394
1394
|
- vendor-src/libleptris/test/xsd/libxml2-cases/ns2_0.xsd
|
|
1395
|
+
- vendor-src/libleptris/test/xsd/libxml2-cases/ns_collision/d.xsd
|
|
1396
|
+
- vendor-src/libleptris/test/xsd/libxml2-cases/ns_collision/w.xsd
|
|
1397
|
+
- vendor-src/libleptris/test/xsd/libxml2-cases/ns_import_attrs/r.xsd
|
|
1398
|
+
- vendor-src/libleptris/test/xsd/libxml2-cases/ns_import_attrs/w.xsd
|
|
1395
1399
|
- vendor-src/libleptris/test/xsd/libxml2-cases/nvdcve_0.xml
|
|
1396
1400
|
- vendor-src/libleptris/test/xsd/libxml2-cases/nvdcve_0.xsd
|
|
1397
1401
|
- vendor-src/libleptris/test/xsd/libxml2-cases/oss-fuzz-51295_0.xml
|