leptris 1.9.323.0-ppc64le-linux → 1.9.331.0-ppc64le-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -0
- data/Rakefile +1 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/ffi.rb +5 -0
- data/lib/leptris/xml/xsd.rb +18 -0
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +166 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/cli/commands/validate.c +5 -7
- data/vendor-src/libleptris/src/include/leptris.h +8 -0
- data/vendor-src/libleptris/src/leptris/dom/node_public.c +1 -1
- data/vendor-src/libleptris/src/leptris/dom/text.c +4 -2
- data/vendor-src/libleptris/src/leptris/dom/text.h +7 -2
- data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +32 -4
- data/vendor-src/libleptris/src/leptris/html/html_parse.c +2 -1
- data/vendor-src/libleptris/src/leptris/leptris.c +7 -2
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +957 -78
- data/vendor-src/libleptris/src/leptris/xsd/content_model.c +20 -2
- data/vendor-src/libleptris/src/leptris/xsd/validate.c +270 -19
- data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +82 -3
- data/vendor-src/libleptris/src/leptris/xslt/xslt_exec.c +1 -1
- data/vendor-src/libleptris/test/CMakeLists.txt +5 -0
- data/vendor-src/libleptris/test/parser/test_parser.cpp +116 -0
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +518 -4
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +2 -2
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
#include "leptris/error.h"
|
|
7
7
|
|
|
8
8
|
#include <cstring>
|
|
9
|
+
#include <cstdlib>
|
|
9
10
|
#include <string>
|
|
10
11
|
|
|
11
12
|
namespace {
|
|
@@ -630,3 +631,118 @@ TEST(ParseDoctype, SubsetBracketInsideQuotesAndComments) {
|
|
|
630
631
|
leptris_document_free(d);
|
|
631
632
|
}
|
|
632
633
|
}
|
|
634
|
+
|
|
635
|
+
/* Nightly-fuzz find (2026-10-09, artifact crash-0a24082b): a text
|
|
636
|
+
* run beginning with NUL bytes collapsed to the EMPTY sentinel —
|
|
637
|
+
* the content pointer read as "" while content_len kept the run's
|
|
638
|
+
* length, so serialize_text_internal walked past the 1-byte global
|
|
639
|
+
* (ASAN global-buffer-overflow). The setter is length-aware now:
|
|
640
|
+
* NUL-leading runs keep a real pointer and serialize verbatim. */
|
|
641
|
+
TEST(ParseNulTextRun, NulLeadingRunSerializesVerbatim) {
|
|
642
|
+
/* between </item> and <item>: eight NULs, newline, two spaces */
|
|
643
|
+
const char xml[] =
|
|
644
|
+
"<?xml version=\"1.0\"?>\n<r>\n <item id=\"1\">Hello</item>"
|
|
645
|
+
"\0\0\0\0\0\0\0\0\n <item id=\"2\">World</item>\n</r>\n";
|
|
646
|
+
size_t len = sizeof(xml) - 1;
|
|
647
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
648
|
+
LeptrisDocument d = leptris_parse_string(xml, len, &st);
|
|
649
|
+
ASSERT_NE(d, nullptr);
|
|
650
|
+
|
|
651
|
+
char* out = leptris_document_serialize(d, NULL);
|
|
652
|
+
ASSERT_NE(out, nullptr);
|
|
653
|
+
/* "Hello</item>" precedes every NUL, so strstr anchors safely;
|
|
654
|
+
* the run that follows must be the verbatim eight NULs + "\n ". */
|
|
655
|
+
const char* hello = strstr(out, "Hello</item>");
|
|
656
|
+
ASSERT_NE(hello, nullptr);
|
|
657
|
+
static const char needle[] =
|
|
658
|
+
"\0\0\0\0\0\0\0\0\n <item id=\"2\"";
|
|
659
|
+
EXPECT_EQ(memcmp(hello + strlen("Hello</item>"), needle,
|
|
660
|
+
sizeof(needle) - 1),
|
|
661
|
+
0)
|
|
662
|
+
<< "NUL-leading run not serialized verbatim";
|
|
663
|
+
leptris_free_string(out);
|
|
664
|
+
leptris_document_free(d);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/* Nightly-fuzz leak-75e0ee81: a duplicate-attribute RECOVER diag
|
|
668
|
+
* (heap-realloc'd by leptris_diag_emit) emitted before an eventual
|
|
669
|
+
* parse failure leaked — the dp fail path freed the line-break
|
|
670
|
+
* table but not the diag array. Leak visibility is the Linux CI
|
|
671
|
+
* ASAN job's (macOS cannot run LSan); this spec pins both paths:
|
|
672
|
+
* the failing parse (fail-path teardown) and the recovered parse
|
|
673
|
+
* (document_free owns the diags). */
|
|
674
|
+
TEST(ParseDiagTeardown, DuplicateAttrDiagBeforeFailureAndRecovery) {
|
|
675
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
676
|
+
/* duplicate attribute (RECOVER diag) then malformed tail */
|
|
677
|
+
const char bad[] = "<r a=\"1\" a=\"2\"<<<<";
|
|
678
|
+
EXPECT_EQ(leptris_parse_string(bad, strlen(bad), &st), nullptr);
|
|
679
|
+
EXPECT_NE(st, LEPTRIS_OK);
|
|
680
|
+
|
|
681
|
+
/* duplicate attribute, well-formed rest: the doc owns the diag */
|
|
682
|
+
const char ok[] = "<r a=\"1\" a=\"2\"/>";
|
|
683
|
+
LeptrisDocument d = leptris_parse_string(ok, strlen(ok), &st);
|
|
684
|
+
ASSERT_NE(d, nullptr);
|
|
685
|
+
leptris_document_free(d);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/* Nightly-fuzz crash-aac3c9bb: the fast-path "<?xml" probe bounded
|
|
689
|
+
* against the ABSOLUTE length while indexing from the first
|
|
690
|
+
* non-whitespace offset — " <?xm" (9 bytes, i=5) read d[i+4]
|
|
691
|
+
* one byte past the caller's buffer. The probe must bound against
|
|
692
|
+
* the remaining span. */
|
|
693
|
+
TEST(ParseFastPath, XmlDeclProbeStaysInBoundsAfterLeadingWhitespace) {
|
|
694
|
+
/* exact 9-byte heap buffer, fuzzer-shaped: a string literal's
|
|
695
|
+
* terminator would land the probe's read in bounds, and stack
|
|
696
|
+
* slots pad to 32 bytes (ASAN cannot see intra-object reads) */
|
|
697
|
+
const char shape[] = {' ', ' ', ' ', ' ', ' ', '<', '?', 'x', 'm'};
|
|
698
|
+
char* xml = (char*)malloc(sizeof(shape));
|
|
699
|
+
ASSERT_NE(xml, nullptr);
|
|
700
|
+
memcpy(xml, shape, sizeof(shape));
|
|
701
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
702
|
+
EXPECT_EQ(leptris_parse_string(xml, sizeof(shape), &st), nullptr);
|
|
703
|
+
EXPECT_NE(st, LEPTRIS_OK);
|
|
704
|
+
free(xml);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/* Nightly-fuzz leak-e3246602: a DOCTYPE internal subset with a
|
|
708
|
+
* DEFAULT attribute declaration grows the DTD model's heap
|
|
709
|
+
* default_decls array — and a subsequent parse failure never
|
|
710
|
+
* transferred p.dtd to the document, so the fail teardown missed
|
|
711
|
+
* it. Pins both paths; leak visibility is the Linux CI ASAN job. */
|
|
712
|
+
TEST(ParseFailTeardown, DtdModelBeforeFailureAndRecovery) {
|
|
713
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
714
|
+
const char bad[] =
|
|
715
|
+
"<!DOCTYPE r [<!ATTLIST r a CDATA \"x\">]><r><";
|
|
716
|
+
EXPECT_EQ(leptris_parse_string(bad, strlen(bad), &st), nullptr);
|
|
717
|
+
EXPECT_NE(st, LEPTRIS_OK);
|
|
718
|
+
|
|
719
|
+
const char ok[] =
|
|
720
|
+
"<!DOCTYPE r [<!ATTLIST r a CDATA \"x\">]><r/>";
|
|
721
|
+
LeptrisDocument d = leptris_parse_string(ok, strlen(ok), &st);
|
|
722
|
+
ASSERT_NE(d, nullptr);
|
|
723
|
+
leptris_document_free(d);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/* Nightly-fuzz leak-168da36a: a second <!DOCTYPE re-entered
|
|
727
|
+
* dp_parse_doctype with the first model still in hand —
|
|
728
|
+
* "dtd = parsed" orphaned it (its realloc'd default_decls array
|
|
729
|
+
* leaked). The lane is lenient about the duplicate, so the FIRST
|
|
730
|
+
* model wins, matching the duplicate-attribute keep-first rule;
|
|
731
|
+
* the replacement is freed. Observable: the first subset's
|
|
732
|
+
* entities keep expanding. */
|
|
733
|
+
TEST(ParseDoctype, SecondDoctypeKeepsFirstModel) {
|
|
734
|
+
const char xml[] =
|
|
735
|
+
"<!DOCTYPE a [<!ENTITY e \"first\">"
|
|
736
|
+
"<!ATTLIST a x CDATA \"d1\">]>"
|
|
737
|
+
"<!DOCTYPE a [<!ENTITY e \"second\">]>"
|
|
738
|
+
"<a>&e;</a>";
|
|
739
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
740
|
+
LeptrisDocument d = leptris_parse_string(xml, strlen(xml), &st);
|
|
741
|
+
ASSERT_NE(d, nullptr);
|
|
742
|
+
LeptrisElement root = leptris_document_root(d);
|
|
743
|
+
ASSERT_NE(root, nullptr);
|
|
744
|
+
const char* text = leptris_element_text(root);
|
|
745
|
+
ASSERT_NE(text, nullptr);
|
|
746
|
+
EXPECT_STREQ(text, "first");
|
|
747
|
+
leptris_document_free(d);
|
|
748
|
+
}
|
|
@@ -130,11 +130,10 @@ TEST(XsdCompile, NullTolerant) {
|
|
|
130
130
|
TEST(Libxml2Corpus, EveryFixtureCompilesOrFailsCleanly) {
|
|
131
131
|
size_t ok = 0, failed = 0;
|
|
132
132
|
for (const std::string& path : fixture_dir(".")) {
|
|
133
|
-
std::string text = slurp(path.c_str());
|
|
134
|
-
ASSERT_FALSE(text.empty()) << path;
|
|
135
133
|
LeptrisStatus st = (LeptrisStatus)0;
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
/* compile_file: xs:include/xs:import schemaLocations
|
|
135
|
+
* resolve against the fixture's own directory */
|
|
136
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(path.c_str(), &st);
|
|
138
137
|
ASSERT_NE(s, (LeptrisXsdSchema)0) << path;
|
|
139
138
|
if (st == LEPTRIS_OK)
|
|
140
139
|
ok++;
|
|
@@ -605,3 +604,518 @@ TEST(XsdDatatypes, AnonymousInlineSimpleTypeOnParticle) {
|
|
|
605
604
|
}
|
|
606
605
|
|
|
607
606
|
} // namespace
|
|
607
|
+
|
|
608
|
+
// ---- slice 6: identity constraints ---------------------------------
|
|
609
|
+
namespace {
|
|
610
|
+
|
|
611
|
+
const char* k_ic_schema =
|
|
612
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
613
|
+
"<xs:element name=\"catalog\">"
|
|
614
|
+
"<xs:complexType>"
|
|
615
|
+
"<xs:sequence>"
|
|
616
|
+
"<xs:element name=\"product\" maxOccurs=\"unbounded\">"
|
|
617
|
+
"<xs:complexType>"
|
|
618
|
+
"<xs:sequence>"
|
|
619
|
+
"<xs:element name=\"partNum\" type=\"xs:string\"/>"
|
|
620
|
+
"</xs:sequence>"
|
|
621
|
+
"<xs:attribute name=\"id\" type=\"xs:string\" use=\"required\"/>"
|
|
622
|
+
"</xs:complexType>"
|
|
623
|
+
"</xs:element>"
|
|
624
|
+
"</xs:sequence>"
|
|
625
|
+
"</xs:complexType>"
|
|
626
|
+
"<xs:key name=\"productId\">"
|
|
627
|
+
"<xs:selector xpath=\"product\"/>"
|
|
628
|
+
"<xs:field xpath=\"@id\"/>"
|
|
629
|
+
"</xs:key>"
|
|
630
|
+
"<xs:keyref name=\"productRef\" refer=\"productId\">"
|
|
631
|
+
"<xs:selector xpath=\"product\"/>"
|
|
632
|
+
"<xs:field xpath=\"partNum\"/>"
|
|
633
|
+
"</xs:keyref>"
|
|
634
|
+
"</xs:element>"
|
|
635
|
+
"</xs:schema>";
|
|
636
|
+
|
|
637
|
+
TEST(XsdIc, UniqueKeysValidate) {
|
|
638
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
639
|
+
LeptrisXsdSchema s =
|
|
640
|
+
leptris_xsd_compile(k_ic_schema, strlen(k_ic_schema), &st);
|
|
641
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
642
|
+
const char* xml =
|
|
643
|
+
"<catalog>"
|
|
644
|
+
"<product id=\"A1\"><partNum>A1</partNum></product>"
|
|
645
|
+
"<product id=\"B2\"><partNum>B2</partNum></product>"
|
|
646
|
+
"</catalog>";
|
|
647
|
+
LeptrisDocument d = leptris_parse_string(xml, strlen(xml), &st);
|
|
648
|
+
ASSERT_NE(d, nullptr);
|
|
649
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 1)
|
|
650
|
+
<< (leptris_xsd_error_count(s) ? leptris_xsd_error_at(s, 0) : "");
|
|
651
|
+
leptris_document_free(d);
|
|
652
|
+
leptris_xsd_free(s);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
TEST(XsdIc, DuplicateKeyReports) {
|
|
656
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
657
|
+
LeptrisXsdSchema s =
|
|
658
|
+
leptris_xsd_compile(k_ic_schema, strlen(k_ic_schema), &st);
|
|
659
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
660
|
+
const char* xml =
|
|
661
|
+
"<catalog>"
|
|
662
|
+
"<product id=\"A1\"><partNum>A1</partNum></product>"
|
|
663
|
+
"<product id=\"A1\"><partNum>zz</partNum></product>"
|
|
664
|
+
"</catalog>";
|
|
665
|
+
LeptrisDocument d = leptris_parse_string(xml, strlen(xml), &st);
|
|
666
|
+
ASSERT_NE(d, nullptr);
|
|
667
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 0);
|
|
668
|
+
size_t n = leptris_xsd_error_count(s);
|
|
669
|
+
int saw_dup = 0;
|
|
670
|
+
for (size_t i = 0; i < n; i++) {
|
|
671
|
+
const char* e = leptris_xsd_error_at(s, i);
|
|
672
|
+
if (e && strstr(e, "duplicate")) saw_dup = 1;
|
|
673
|
+
}
|
|
674
|
+
EXPECT_TRUE(saw_dup);
|
|
675
|
+
leptris_document_free(d);
|
|
676
|
+
leptris_xsd_free(s);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
TEST(XsdIc, UnresolvedKeyrefReports) {
|
|
680
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
681
|
+
LeptrisXsdSchema s =
|
|
682
|
+
leptris_xsd_compile(k_ic_schema, strlen(k_ic_schema), &st);
|
|
683
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
684
|
+
const char* xml =
|
|
685
|
+
"<catalog>"
|
|
686
|
+
"<product id=\"A1\"><partNum>NOPE</partNum></product>"
|
|
687
|
+
"</catalog>";
|
|
688
|
+
LeptrisDocument d = leptris_parse_string(xml, strlen(xml), &st);
|
|
689
|
+
ASSERT_NE(d, nullptr);
|
|
690
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 0);
|
|
691
|
+
size_t n = leptris_xsd_error_count(s);
|
|
692
|
+
int saw_ref = 0;
|
|
693
|
+
for (size_t i = 0; i < n; i++) {
|
|
694
|
+
const char* e = leptris_xsd_error_at(s, i);
|
|
695
|
+
if (e && strstr(e, "keyref")) saw_ref = 1;
|
|
696
|
+
}
|
|
697
|
+
EXPECT_TRUE(saw_ref);
|
|
698
|
+
leptris_document_free(d);
|
|
699
|
+
leptris_xsd_free(s);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
TEST(XsdIc, KeyRequiresFieldValues) {
|
|
703
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
704
|
+
const char* xsd =
|
|
705
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
706
|
+
"<xs:element name=\"r\">"
|
|
707
|
+
"<xs:complexType><xs:sequence>"
|
|
708
|
+
"<xs:element name=\"item\" maxOccurs=\"unbounded\"/>"
|
|
709
|
+
"</xs:sequence></xs:complexType>"
|
|
710
|
+
"<xs:key name=\"k\">"
|
|
711
|
+
"<xs:selector xpath=\"item\"/>"
|
|
712
|
+
"<xs:field xpath=\"@id\"/>"
|
|
713
|
+
"</xs:key>"
|
|
714
|
+
"</xs:element></xs:schema>";
|
|
715
|
+
LeptrisXsdSchema s = leptris_xsd_compile(xsd, strlen(xsd), &st);
|
|
716
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
717
|
+
const char* xml = "<r><item/><item id=\"a\"/></r>";
|
|
718
|
+
LeptrisDocument d = leptris_parse_string(xml, strlen(xml), &st);
|
|
719
|
+
ASSERT_NE(d, nullptr);
|
|
720
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 0); /* missing field */
|
|
721
|
+
leptris_document_free(d);
|
|
722
|
+
leptris_xsd_free(s);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
} // namespace
|
|
726
|
+
|
|
727
|
+
// ---- local particle declarations -----------------------------------
|
|
728
|
+
namespace {
|
|
729
|
+
|
|
730
|
+
/* item is declared ONLY as a particle of orderT — no global
|
|
731
|
+
* xs:element named item exists — so its attributes and children
|
|
732
|
+
* must validate against itemT's rows through the particle's type. */
|
|
733
|
+
const char* k_local_schema =
|
|
734
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
735
|
+
"<xs:complexType name=\"itemT\">"
|
|
736
|
+
"<xs:sequence>"
|
|
737
|
+
"<xs:element name=\"sku\" type=\"xs:token\"/>"
|
|
738
|
+
"<xs:element name=\"qty\" type=\"xs:integer\"/>"
|
|
739
|
+
"</xs:sequence>"
|
|
740
|
+
"<xs:attribute name=\"id\" type=\"xs:integer\" use=\"required\"/>"
|
|
741
|
+
"</xs:complexType>"
|
|
742
|
+
"<xs:complexType name=\"orderT\">"
|
|
743
|
+
"<xs:sequence>"
|
|
744
|
+
"<xs:element name=\"item\" type=\"itemT\" maxOccurs=\"unbounded\"/>"
|
|
745
|
+
"</xs:sequence>"
|
|
746
|
+
"<xs:attribute name=\"ref\" type=\"xs:string\"/>"
|
|
747
|
+
"</xs:complexType>"
|
|
748
|
+
"<xs:element name=\"order\" type=\"orderT\"/>"
|
|
749
|
+
"</xs:schema>";
|
|
750
|
+
|
|
751
|
+
TEST(XsdLocal, LocalChildAttributesValidate) {
|
|
752
|
+
EXPECT_EQ(validate_doc(k_local_schema,
|
|
753
|
+
"<order><item id=\"5\"><sku>a</sku>"
|
|
754
|
+
"<qty>2</qty></item></order>"), 1);
|
|
755
|
+
EXPECT_EQ(validate_doc(k_local_schema,
|
|
756
|
+
"<order><item id=\"nan\"><sku>a</sku>"
|
|
757
|
+
"<qty>2</qty></item></order>"), 0);
|
|
758
|
+
EXPECT_EQ(validate_doc(k_local_schema,
|
|
759
|
+
"<order><item><sku>a</sku>"
|
|
760
|
+
"<qty>2</qty></item></order>"), 0);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
TEST(XsdLocal, LocalChildContentModelValidates) {
|
|
764
|
+
EXPECT_EQ(validate_doc(k_local_schema,
|
|
765
|
+
"<order><item id=\"5\"><qty>2</qty>"
|
|
766
|
+
"<sku>a</sku></item></order>"), 0);
|
|
767
|
+
EXPECT_EQ(validate_doc(k_local_schema,
|
|
768
|
+
"<order><item id=\"5\"><sku>a</sku>"
|
|
769
|
+
"<qty>nan</qty></item></order>"), 0);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
} // namespace
|
|
773
|
+
|
|
774
|
+
// ---- tier-1 charter: union / list simple-type derivation -----------
|
|
775
|
+
namespace {
|
|
776
|
+
|
|
777
|
+
const char* k_ul_schema =
|
|
778
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
779
|
+
"<xs:simpleType name=\"ints\">"
|
|
780
|
+
"<xs:list itemType=\"xs:integer\"/>"
|
|
781
|
+
"</xs:simpleType>"
|
|
782
|
+
"<xs:simpleType name=\"alpha\">"
|
|
783
|
+
"<xs:restriction base=\"xs:string\">"
|
|
784
|
+
"<xs:pattern value=\"[a-z]+\"/>"
|
|
785
|
+
"</xs:restriction>"
|
|
786
|
+
"</xs:simpleType>"
|
|
787
|
+
"<xs:simpleType name=\"code\">"
|
|
788
|
+
"<xs:union memberTypes=\"xs:integer alpha\"/>"
|
|
789
|
+
"</xs:simpleType>"
|
|
790
|
+
"<xs:element name=\"vals\" type=\"ints\"/>"
|
|
791
|
+
"<xs:element name=\"c\" type=\"code\"/>"
|
|
792
|
+
"</xs:schema>";
|
|
793
|
+
|
|
794
|
+
TEST(XsdDatatypes, ListDerivationValidatesEveryItem) {
|
|
795
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
796
|
+
LeptrisXsdSchema s =
|
|
797
|
+
leptris_xsd_compile(k_ul_schema, strlen(k_ul_schema), &st);
|
|
798
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
799
|
+
EXPECT_EQ(leptris_xsd_simple_valid(s, "ints", "1 2 3"), 1);
|
|
800
|
+
EXPECT_EQ(leptris_xsd_simple_valid(s, "ints", "1 x 3"), 0);
|
|
801
|
+
leptris_xsd_free(s);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
TEST(XsdDatatypes, UnionDerivationAcceptsAnyMember) {
|
|
805
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
806
|
+
LeptrisXsdSchema s =
|
|
807
|
+
leptris_xsd_compile(k_ul_schema, strlen(k_ul_schema), &st);
|
|
808
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
809
|
+
EXPECT_EQ(leptris_xsd_simple_valid(s, "code", "42"), 1);
|
|
810
|
+
EXPECT_EQ(leptris_xsd_simple_valid(s, "code", "abc"), 1);
|
|
811
|
+
EXPECT_EQ(leptris_xsd_simple_valid(s, "code", "42x"), 0);
|
|
812
|
+
leptris_xsd_free(s);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
TEST(XsdValidate, UnionAndListValidateInDocuments) {
|
|
816
|
+
EXPECT_EQ(validate_doc(k_ul_schema, "<vals>1 2 3</vals>"), 1);
|
|
817
|
+
EXPECT_EQ(validate_doc(k_ul_schema, "<vals>1 x</vals>"), 0);
|
|
818
|
+
EXPECT_EQ(validate_doc(k_ul_schema, "<c>abc</c>"), 1);
|
|
819
|
+
EXPECT_EQ(validate_doc(k_ul_schema, "<c>99</c>"), 1);
|
|
820
|
+
EXPECT_EQ(validate_doc(k_ul_schema, "<c>1.5</c>"), 0);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/* inline anonymous union member (no memberTypes for it) */
|
|
824
|
+
TEST(XsdDatatypes, UnionInlineAnonymousMember) {
|
|
825
|
+
const char* x =
|
|
826
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
827
|
+
"<xs:simpleType name=\"combo\">"
|
|
828
|
+
"<xs:union memberTypes=\"xs:integer\">"
|
|
829
|
+
"<xs:simpleType><xs:restriction base=\"xs:string\">"
|
|
830
|
+
"<xs:enumeration value=\"yes\"/>"
|
|
831
|
+
"<xs:enumeration value=\"no\"/>"
|
|
832
|
+
"</xs:restriction></xs:simpleType>"
|
|
833
|
+
"</xs:union>"
|
|
834
|
+
"</xs:simpleType>"
|
|
835
|
+
"<xs:element name=\"q\" type=\"combo\"/>"
|
|
836
|
+
"</xs:schema>";
|
|
837
|
+
EXPECT_EQ(validate_doc(x, "<q>3</q>"), 1);
|
|
838
|
+
EXPECT_EQ(validate_doc(x, "<q>yes</q>"), 1);
|
|
839
|
+
EXPECT_EQ(validate_doc(x, "<q>maybe</q>"), 0);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
} // namespace
|
|
844
|
+
|
|
845
|
+
// ---- tier-1 charter: named groups + attribute groups + attr refs --
|
|
846
|
+
namespace {
|
|
847
|
+
|
|
848
|
+
const char* k_grp_schema =
|
|
849
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
850
|
+
"<xs:group name=\"meta\">"
|
|
851
|
+
"<xs:sequence>"
|
|
852
|
+
"<xs:element name=\"title\" type=\"xs:token\"/>"
|
|
853
|
+
"<xs:element name=\"date\" type=\"xs:date\"/>"
|
|
854
|
+
"</xs:sequence>"
|
|
855
|
+
"</xs:group>"
|
|
856
|
+
"<xs:attribute name=\"rev\" type=\"xs:integer\"/>"
|
|
857
|
+
"<xs:attributeGroup name=\"common\">"
|
|
858
|
+
"<xs:attribute name=\"id\" type=\"xs:integer\" use=\"required\"/>"
|
|
859
|
+
"<xs:attribute name=\"lang\" type=\"xs:string\"/>"
|
|
860
|
+
"</xs:attributeGroup>"
|
|
861
|
+
"<xs:complexType name=\"docT\">"
|
|
862
|
+
"<xs:sequence>"
|
|
863
|
+
"<xs:group ref=\"meta\"/>"
|
|
864
|
+
"<xs:element name=\"body\" type=\"xs:string\"/>"
|
|
865
|
+
"</xs:sequence>"
|
|
866
|
+
"<xs:attributeGroup ref=\"common\"/>"
|
|
867
|
+
"<xs:attribute ref=\"rev\"/>"
|
|
868
|
+
"</xs:complexType>"
|
|
869
|
+
"<xs:element name=\"doc\" type=\"docT\"/>"
|
|
870
|
+
"</xs:schema>";
|
|
871
|
+
|
|
872
|
+
TEST(XsdContent, NamedModelGroupSplices) {
|
|
873
|
+
EXPECT_EQ(validate_doc(k_grp_schema,
|
|
874
|
+
"<doc id=\"1\" lang=\"en\" rev=\"2\">"
|
|
875
|
+
"<title>t</title><date>2026-01-01</date>"
|
|
876
|
+
"<body>b</body></doc>"), 1);
|
|
877
|
+
/* body before the spliced group content */
|
|
878
|
+
EXPECT_EQ(validate_doc(k_grp_schema,
|
|
879
|
+
"<doc id=\"1\"><body>b</body>"
|
|
880
|
+
"<title>t</title><date>2026-01-01</date>"
|
|
881
|
+
"</doc>"), 0);
|
|
882
|
+
/* missing a group member */
|
|
883
|
+
EXPECT_EQ(validate_doc(k_grp_schema,
|
|
884
|
+
"<doc id=\"1\"><title>t</title>"
|
|
885
|
+
"<body>b</body></doc>"), 0);
|
|
886
|
+
/* group member text types ride the splice */
|
|
887
|
+
EXPECT_EQ(validate_doc(k_grp_schema,
|
|
888
|
+
"<doc id=\"1\"><title>t</title>"
|
|
889
|
+
"<date>not-a-date</date><body>b</body>"
|
|
890
|
+
"</doc>"), 0);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
TEST(XsdValidate, AttributeGroupRowsApply) {
|
|
894
|
+
EXPECT_EQ(validate_doc(k_grp_schema,
|
|
895
|
+
"<doc><title>t</title>"
|
|
896
|
+
"<date>2026-01-01</date><body>b</body></doc>"), 0);
|
|
897
|
+
EXPECT_EQ(validate_doc(k_grp_schema,
|
|
898
|
+
"<doc id=\"x\"><title>t</title>"
|
|
899
|
+
"<date>2026-01-01</date><body>b</body></doc>"),
|
|
900
|
+
0);
|
|
901
|
+
/* the referenced top-level attribute enforces its type */
|
|
902
|
+
EXPECT_EQ(validate_doc(k_grp_schema,
|
|
903
|
+
"<doc id=\"1\" rev=\"x\"><title>t</title>"
|
|
904
|
+
"<date>2026-01-01</date><body>b</body></doc>"),
|
|
905
|
+
0);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
} // namespace
|
|
909
|
+
|
|
910
|
+
// ---- tier-1 charter: complexContent / simpleContent derivation -----
|
|
911
|
+
namespace {
|
|
912
|
+
|
|
913
|
+
const char* k_deriv_schema =
|
|
914
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
915
|
+
"<xs:complexType name=\"baseT\">"
|
|
916
|
+
"<xs:sequence>"
|
|
917
|
+
"<xs:element name=\"a\" type=\"xs:token\"/>"
|
|
918
|
+
"<xs:element name=\"b\" type=\"xs:token\"/>"
|
|
919
|
+
"</xs:sequence>"
|
|
920
|
+
"<xs:attribute name=\"x\" type=\"xs:integer\"/>"
|
|
921
|
+
"</xs:complexType>"
|
|
922
|
+
"<xs:complexType name=\"extT\">"
|
|
923
|
+
"<xs:complexContent>"
|
|
924
|
+
"<xs:extension base=\"baseT\">"
|
|
925
|
+
"<xs:sequence>"
|
|
926
|
+
"<xs:element name=\"c\" type=\"xs:integer\"/>"
|
|
927
|
+
"</xs:sequence>"
|
|
928
|
+
"<xs:attribute name=\"y\" type=\"xs:string\"/>"
|
|
929
|
+
"</xs:extension>"
|
|
930
|
+
"</xs:complexContent>"
|
|
931
|
+
"</xs:complexType>"
|
|
932
|
+
"<xs:complexType name=\"rstrT\">"
|
|
933
|
+
"<xs:complexContent>"
|
|
934
|
+
"<xs:restriction base=\"baseT\">"
|
|
935
|
+
"<xs:sequence>"
|
|
936
|
+
"<xs:element name=\"a\" type=\"xs:token\"/>"
|
|
937
|
+
"</xs:sequence>"
|
|
938
|
+
"</xs:restriction>"
|
|
939
|
+
"</xs:complexContent>"
|
|
940
|
+
"</xs:complexType>"
|
|
941
|
+
"<xs:complexType name=\"labelT\">"
|
|
942
|
+
"<xs:simpleContent>"
|
|
943
|
+
"<xs:extension base=\"xs:string\">"
|
|
944
|
+
"<xs:attribute name=\"lang\" type=\"xs:string\" use=\"required\"/>"
|
|
945
|
+
"</xs:extension>"
|
|
946
|
+
"</xs:simpleContent>"
|
|
947
|
+
"</xs:complexType>"
|
|
948
|
+
"<xs:element name=\"e\" type=\"extT\"/>"
|
|
949
|
+
"<xs:element name=\"r\" type=\"rstrT\"/>"
|
|
950
|
+
"<xs:element name=\"l\" type=\"labelT\"/>"
|
|
951
|
+
"</xs:schema>";
|
|
952
|
+
|
|
953
|
+
TEST(XsdValidate, ExtensionSplicesBaseContentAndAttrs) {
|
|
954
|
+
EXPECT_EQ(validate_doc(k_deriv_schema,
|
|
955
|
+
"<e x=\"1\" y=\"s\"><a>t</a><b>u</b>"
|
|
956
|
+
"<c>3</c></e>"), 1);
|
|
957
|
+
/* base child still required after extension */
|
|
958
|
+
EXPECT_EQ(validate_doc(k_deriv_schema,
|
|
959
|
+
"<e x=\"1\" y=\"s\"><a>t</a>"
|
|
960
|
+
"<c>3</c></e>"), 0);
|
|
961
|
+
/* derived child appends after the base sequence */
|
|
962
|
+
EXPECT_EQ(validate_doc(k_deriv_schema,
|
|
963
|
+
"<e x=\"1\" y=\"s\"><c>3</c><a>t</a>"
|
|
964
|
+
"<b>u</b></e>"), 0);
|
|
965
|
+
/* base attribute rows ride the derivation */
|
|
966
|
+
EXPECT_EQ(validate_doc(k_deriv_schema,
|
|
967
|
+
"<e x=\"z\" y=\"s\"><a>t</a><b>u</b>"
|
|
968
|
+
"<c>3</c></e>"), 0);
|
|
969
|
+
/* derived-only attribute optional */
|
|
970
|
+
EXPECT_EQ(validate_doc(k_deriv_schema,
|
|
971
|
+
"<e x=\"1\"><a>t</a><b>u</b>"
|
|
972
|
+
"<c>3</c></e>"), 1);
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
TEST(XsdValidate, RestrictionReplacesContentModel) {
|
|
976
|
+
EXPECT_EQ(validate_doc(k_deriv_schema,
|
|
977
|
+
"<r x=\"1\"><a>t</a></r>"), 1);
|
|
978
|
+
/* the restricted-away child is no longer allowed */
|
|
979
|
+
EXPECT_EQ(validate_doc(k_deriv_schema,
|
|
980
|
+
"<r x=\"1\"><a>t</a><b>u</b></r>"), 0);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
TEST(XsdValidate, SimpleContentTextAndAttrs) {
|
|
984
|
+
EXPECT_EQ(validate_doc(k_deriv_schema,
|
|
985
|
+
"<l lang=\"en\">hello</l>"), 1);
|
|
986
|
+
EXPECT_EQ(validate_doc(k_deriv_schema,
|
|
987
|
+
"<l>hello</l>"), 0);
|
|
988
|
+
EXPECT_EQ(validate_doc(k_deriv_schema,
|
|
989
|
+
"<l lang=\"en\">42</l>"), 1);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
} // namespace
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
// ---- tier-1 charter: fixed/default + substitutionGroup -------------
|
|
996
|
+
namespace {
|
|
997
|
+
|
|
998
|
+
const char* k_fd_schema =
|
|
999
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
1000
|
+
"<xs:complexType name=\"orderT\">"
|
|
1001
|
+
"<xs:sequence>"
|
|
1002
|
+
"<xs:element name=\"item\" type=\"xs:token\"/>"
|
|
1003
|
+
"</xs:sequence>"
|
|
1004
|
+
"<xs:attribute name=\"country\" type=\"xs:string\" fixed=\"US\"/>"
|
|
1005
|
+
"<xs:attribute name=\"prio\" type=\"xs:integer\" default=\"2\"/>"
|
|
1006
|
+
"</xs:complexType>"
|
|
1007
|
+
"<xs:element name=\"order\" type=\"orderT\"/>"
|
|
1008
|
+
"<xs:element name=\"ship\" type=\"xs:string\" fixed=\"air\"/>"
|
|
1009
|
+
"</xs:schema>";
|
|
1010
|
+
|
|
1011
|
+
TEST(XsdValidate, FixedAttributeValueEnforced) {
|
|
1012
|
+
EXPECT_EQ(validate_doc(k_fd_schema,
|
|
1013
|
+
"<order country=\"US\"><item>x</item>"
|
|
1014
|
+
"</order>"), 1);
|
|
1015
|
+
EXPECT_EQ(validate_doc(k_fd_schema,
|
|
1016
|
+
"<order country=\"US\" prio=\"7\">"
|
|
1017
|
+
"<item>x</item></order>"), 1);
|
|
1018
|
+
EXPECT_EQ(validate_doc(k_fd_schema,
|
|
1019
|
+
"<order country=\"DE\"><item>x</item>"
|
|
1020
|
+
"</order>"), 0);
|
|
1021
|
+
EXPECT_EQ(validate_doc(k_fd_schema,
|
|
1022
|
+
"<order><item>x</item></order>"), 1);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
TEST(XsdValidate, FixedElementTextEnforced) {
|
|
1026
|
+
EXPECT_EQ(validate_doc(k_fd_schema, "<ship>air</ship>"), 1);
|
|
1027
|
+
EXPECT_EQ(validate_doc(k_fd_schema, "<ship>sea</ship>"), 0);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
const char* k_subst_schema =
|
|
1031
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
1032
|
+
"<xs:complexType name=\"boxT\">"
|
|
1033
|
+
"<xs:sequence>"
|
|
1034
|
+
"<xs:element name=\"head\" type=\"xs:token\"/>"
|
|
1035
|
+
"</xs:sequence>"
|
|
1036
|
+
"</xs:complexType>"
|
|
1037
|
+
"<xs:element name=\"head\" type=\"xs:token\"/>"
|
|
1038
|
+
"<xs:element name=\"alt\" type=\"xs:token\" substitutionGroup=\"head\"/>"
|
|
1039
|
+
"<xs:element name=\"box\" type=\"boxT\"/>"
|
|
1040
|
+
"</xs:schema>";
|
|
1041
|
+
|
|
1042
|
+
TEST(XsdValidate, SubstitutionGroupMembersBind) {
|
|
1043
|
+
EXPECT_EQ(validate_doc(k_subst_schema,
|
|
1044
|
+
"<box><head>x</head></box>"), 1);
|
|
1045
|
+
EXPECT_EQ(validate_doc(k_subst_schema,
|
|
1046
|
+
"<box><alt>y</alt></box>"), 1);
|
|
1047
|
+
EXPECT_EQ(validate_doc(k_subst_schema,
|
|
1048
|
+
"<box><other>z</other></box>"), 0);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
} // namespace
|
|
1052
|
+
|
|
1053
|
+
// ---- tier-1 charter: include/import via compile_file ---------------
|
|
1054
|
+
namespace {
|
|
1055
|
+
|
|
1056
|
+
TEST(XsdCompileFile, IncludeResolvesRelativeSchemaLocation) {
|
|
1057
|
+
std::string dir = ::testing::TempDir();
|
|
1058
|
+
std::string common = dir + "xsdcommon.xsd";
|
|
1059
|
+
std::string main = dir + "xsdmain.xsd";
|
|
1060
|
+
FILE* f1 = fopen(common.c_str(), "wb");
|
|
1061
|
+
ASSERT_NE(f1, nullptr);
|
|
1062
|
+
const char* common_text =
|
|
1063
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
1064
|
+
"<xs:complexType name=\"itemT\">"
|
|
1065
|
+
"<xs:sequence>"
|
|
1066
|
+
"<xs:element name=\"sku\" type=\"xs:token\"/>"
|
|
1067
|
+
"</xs:sequence>"
|
|
1068
|
+
"<xs:attribute name=\"id\" type=\"xs:integer\" use=\"required\"/>"
|
|
1069
|
+
"</xs:complexType>"
|
|
1070
|
+
"</xs:schema>";
|
|
1071
|
+
fwrite(common_text, 1, strlen(common_text), f1);
|
|
1072
|
+
fclose(f1);
|
|
1073
|
+
FILE* f2 = fopen(main.c_str(), "wb");
|
|
1074
|
+
ASSERT_NE(f2, nullptr);
|
|
1075
|
+
const char* main_text =
|
|
1076
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
1077
|
+
"<xs:include schemaLocation=\"xsdcommon.xsd\"/>"
|
|
1078
|
+
"<xs:complexType name=\"listT\">"
|
|
1079
|
+
"<xs:sequence>"
|
|
1080
|
+
"<xs:element name=\"item\" type=\"itemT\""
|
|
1081
|
+
" maxOccurs=\"unbounded\"/>"
|
|
1082
|
+
"</xs:sequence>"
|
|
1083
|
+
"</xs:complexType>"
|
|
1084
|
+
"<xs:element name=\"list\" type=\"listT\"/>"
|
|
1085
|
+
"</xs:schema>";
|
|
1086
|
+
fwrite(main_text, 1, strlen(main_text), f2);
|
|
1087
|
+
fclose(f2);
|
|
1088
|
+
|
|
1089
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1090
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(main.c_str(), &st);
|
|
1091
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
1092
|
+
/* the included declaration participates: itemT's rows type the
|
|
1093
|
+
* particle's attributes and its content model applies */
|
|
1094
|
+
const char* good =
|
|
1095
|
+
"<list><item id=\"5\"><sku>a</sku></item></list>";
|
|
1096
|
+
LeptrisDocument d =
|
|
1097
|
+
leptris_parse_string(good, strlen(good), &st);
|
|
1098
|
+
ASSERT_NE(d, nullptr);
|
|
1099
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 1);
|
|
1100
|
+
const char* badx =
|
|
1101
|
+
"<list><item id=\"x\"><sku>a</sku></item></list>";
|
|
1102
|
+
LeptrisDocument bad =
|
|
1103
|
+
leptris_parse_string(badx, strlen(badx), &st);
|
|
1104
|
+
ASSERT_NE(bad, nullptr);
|
|
1105
|
+
EXPECT_EQ(leptris_xsd_validate(s, bad), 0);
|
|
1106
|
+
leptris_document_free(d);
|
|
1107
|
+
leptris_document_free(bad);
|
|
1108
|
+
leptris_xsd_free(s);
|
|
1109
|
+
remove(common.c_str());
|
|
1110
|
+
remove(main.c_str());
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
TEST(XsdCompileFile, MissingFileIsNullWithStatus) {
|
|
1114
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1115
|
+
EXPECT_EQ(leptris_xsd_compile_file("/no/such/schema.xsd", &st),
|
|
1116
|
+
(LeptrisXsdSchema)0);
|
|
1117
|
+
EXPECT_NE(st, LEPTRIS_OK);
|
|
1118
|
+
EXPECT_EQ(leptris_xsd_compile_file(NULL, &st), (LeptrisXsdSchema)0);
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
} // namespace
|
|
@@ -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.331",
|
|
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",
|