leptris 1.9.356.0-arm-linux → 1.9.360.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.
- checksums.yaml +4 -4
- data/README.adoc +13 -5
- data/Rakefile +1 -1
- data/ext/leptris/native/native.c +353 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/cdata.rb +3 -0
- data/lib/leptris/xml/comment.rb +3 -0
- data/lib/leptris/xml/declaration.rb +64 -0
- data/lib/leptris/xml/doc_type.rb +33 -1
- data/lib/leptris/xml/document.rb +77 -2
- data/lib/leptris/xml/element.rb +21 -1
- data/lib/leptris/xml/entity_reference.rb +3 -0
- data/lib/leptris/xml/native.so +0 -0
- data/lib/leptris/xml/node_set.rb +22 -0
- data/lib/leptris/xml/processing_instruction.rb +3 -0
- data/lib/leptris/xml/sax/parser.rb +102 -78
- data/lib/leptris/xml/text.rb +4 -0
- data/lib/leptris/xml.rb +14 -0
- data/lib/libleptris.so +0 -0
- data/scripts/gem_smoke.rb +6 -3
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +95 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/TODO.xslt-full/REMAINING.md +37 -18
- data/vendor-src/libleptris/cli/commands/validate.c +15 -2
- data/vendor-src/libleptris/src/include/leptris.h +60 -4
- data/vendor-src/libleptris/src/leptris/dtd/content_check.c +280 -144
- data/vendor-src/libleptris/src/leptris/dtd/parser.c +17 -4
- data/vendor-src/libleptris/src/leptris/rng/parse.c +53 -8
- data/vendor-src/libleptris/src/leptris/rng/validate.c +63 -21
- data/vendor-src/libleptris/src/leptris/xinclude/xinclude.c +304 -12
- data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +30 -0
- data/vendor-src/libleptris/src/leptris/xpath/evaluator.h +11 -0
- data/vendor-src/libleptris/src/leptris/xpath/evaluator_axes.c +3 -3
- data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +4 -20
- data/vendor-src/libleptris/src/leptris/xpath/parser.c +4 -1
- data/vendor-src/libleptris/src/leptris/xpath/vm.c +41 -11
- data/vendor-src/libleptris/src/leptris/xpath/xpath_compiled.c +4 -3
- data/vendor-src/libleptris/src/leptris/xpath/xpath_public.c +2 -1
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +981 -38
- data/vendor-src/libleptris/src/leptris/xsd/content_model.c +15 -3
- data/vendor-src/libleptris/src/leptris/xsd/validate.c +27 -9
- data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +1 -0
- data/vendor-src/libleptris/test/cli/test_cli.cpp +50 -14
- data/vendor-src/libleptris/test/dtd/test_dtd_validate.cpp +80 -4
- data/vendor-src/libleptris/test/rng/include-cases/attr-text-choice.rng +18 -0
- data/vendor-src/libleptris/test/rng/include-cases/dup-inc-mid.rng +7 -0
- data/vendor-src/libleptris/test/rng/include-cases/dup-inc-shared.rng +5 -0
- data/vendor-src/libleptris/test/rng/include-cases/dup-inc-top.rng +6 -0
- data/vendor-src/libleptris/test/rng/test_rng.cpp +101 -0
- data/vendor-src/libleptris/test/xinclude/test_xinclude.cpp +261 -0
- data/vendor-src/libleptris/test/xpath/test_xpath.cpp +169 -0
- data/vendor-src/libleptris/test/xpath/test_xpath_conformance.cpp +8 -1
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +128 -11
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +7 -2
|
@@ -4,7 +4,31 @@
|
|
|
4
4
|
#include "leptris.h"
|
|
5
5
|
#include <cstring>
|
|
6
6
|
#include <cstdio>
|
|
7
|
+
#include <cstdlib>
|
|
7
8
|
#include <string>
|
|
9
|
+
#include <errno.h>
|
|
10
|
+
#ifdef _WIN32
|
|
11
|
+
#include <direct.h>
|
|
12
|
+
#define XI_MKDIR(p) _mkdir(p)
|
|
13
|
+
#define XI_RMDIR(p) _rmdir(p)
|
|
14
|
+
#else
|
|
15
|
+
#include <sys/stat.h>
|
|
16
|
+
#include <sys/types.h>
|
|
17
|
+
#define XI_MKDIR(p) mkdir(p, 0755)
|
|
18
|
+
#define XI_RMDIR(p) rmdir(p)
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
/* mkdir -p for the (short) fixture paths; EEXIST is fine. */
|
|
22
|
+
static void xi_mkdir_p(const std::string& path) {
|
|
23
|
+
if (path.empty()) return;
|
|
24
|
+
for (size_t i = 1; i <= path.size(); i++) {
|
|
25
|
+
if (i == path.size() || path[i] == '/' || path[i] == '\\') {
|
|
26
|
+
std::string prefix = path.substr(0, i);
|
|
27
|
+
XI_MKDIR(prefix.c_str()); /* EEXIST tolerated */
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
8
32
|
#if defined(_WIN32)
|
|
9
33
|
#include <process.h>
|
|
10
34
|
#else
|
|
@@ -413,6 +437,243 @@ TEST(XIncludeProcess, ParseXmlRecursiveIncludesNestedXi) {
|
|
|
413
437
|
remove(outer_path);
|
|
414
438
|
}
|
|
415
439
|
|
|
440
|
+
// ---- TODO.assemble 03: xml:base chains ---------------------------------
|
|
441
|
+
|
|
442
|
+
TEST(XIncludeXmlBase, AncestorXmlBaseResolvesRelativeHref) {
|
|
443
|
+
/* The include rides the NEAREST xml:base ancestor merged over
|
|
444
|
+
* the document base — RFC 3986 §5.2 — not the document location
|
|
445
|
+
* alone. */
|
|
446
|
+
const char inner_xml[] = "<inner>base-dir-content</inner>";
|
|
447
|
+
const char* dir = "/tmp/leptris_xi_base";
|
|
448
|
+
char target[256];
|
|
449
|
+
snprintf(target, sizeof(target), "%s/inner.xml", dir);
|
|
450
|
+
XI_MKDIR(dir);
|
|
451
|
+
FILE* f = fopen(target, "wb");
|
|
452
|
+
ASSERT_NE(f, nullptr);
|
|
453
|
+
fwrite(inner_xml, 1, std::strlen(inner_xml), f);
|
|
454
|
+
fclose(f);
|
|
455
|
+
|
|
456
|
+
const char xml[] =
|
|
457
|
+
"<root xmlns:xi='http://www.w3.org/2001/XInclude'>"
|
|
458
|
+
" <wrapper xml:base='/tmp/leptris_xi_base/'>"
|
|
459
|
+
" <xi:include href='inner.xml'/>"
|
|
460
|
+
" </wrapper>"
|
|
461
|
+
"</root>";
|
|
462
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
463
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
464
|
+
ASSERT_NE(doc, nullptr);
|
|
465
|
+
|
|
466
|
+
EXPECT_EQ(leptris_xinclude_process(doc, nullptr), LEPTRIS_OK);
|
|
467
|
+
|
|
468
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
469
|
+
LeptrisElement wrapper = leptris_element_first_child_any(root);
|
|
470
|
+
ASSERT_NE(wrapper, nullptr);
|
|
471
|
+
LeptrisElement inner = leptris_element_first_child_any(wrapper);
|
|
472
|
+
ASSERT_NE(inner, nullptr);
|
|
473
|
+
EXPECT_STREQ(leptris_element_name(inner), "inner");
|
|
474
|
+
EXPECT_STREQ(leptris_element_text(inner), "base-dir-content");
|
|
475
|
+
|
|
476
|
+
leptris_document_free(doc);
|
|
477
|
+
remove(target);
|
|
478
|
+
XI_RMDIR(dir);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
TEST(XIncludeXmlBase, RelativeXmlBaseMergesOverDocBase) {
|
|
482
|
+
/* A RELATIVE xml:base resolves against the document's base_url
|
|
483
|
+
* before the href resolves against it. */
|
|
484
|
+
const char inner_xml[] = "<inner>rel</inner>";
|
|
485
|
+
const char* dir = "/tmp/leptris_xi_rel/sub";
|
|
486
|
+
char target[256];
|
|
487
|
+
snprintf(target, sizeof(target), "%s/inner.xml", dir);
|
|
488
|
+
xi_mkdir_p(dir);
|
|
489
|
+
FILE* f = fopen(target, "wb");
|
|
490
|
+
ASSERT_NE(f, nullptr);
|
|
491
|
+
fwrite(inner_xml, 1, std::strlen(inner_xml), f);
|
|
492
|
+
fclose(f);
|
|
493
|
+
|
|
494
|
+
const char xml[] =
|
|
495
|
+
"<root xmlns:xi='http://www.w3.org/2001/XInclude'>"
|
|
496
|
+
" <xi:include href='inner.xml' xml:base='sub/'/>"
|
|
497
|
+
"</root>";
|
|
498
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
499
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
500
|
+
ASSERT_NE(doc, nullptr);
|
|
501
|
+
|
|
502
|
+
EXPECT_EQ(leptris_xinclude_process_opts(doc, "/tmp/leptris_xi_rel/",
|
|
503
|
+
nullptr),
|
|
504
|
+
LEPTRIS_OK);
|
|
505
|
+
|
|
506
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
507
|
+
LeptrisElement inner = leptris_element_first_child_any(root);
|
|
508
|
+
ASSERT_NE(inner, nullptr);
|
|
509
|
+
EXPECT_STREQ(leptris_element_text(inner), "rel");
|
|
510
|
+
|
|
511
|
+
leptris_document_free(doc);
|
|
512
|
+
remove(target);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
TEST(XIncludeXmlBase, NestedIncludeResolvesAgainstIncludedDocDir) {
|
|
516
|
+
/* A doc included from dirA includes 'peer.xml' relatively — the
|
|
517
|
+
* peer resolves against dirA (the included doc's own location),
|
|
518
|
+
* not the includer's directory. */
|
|
519
|
+
const char* dir = "/tmp/leptris_xi_nested";
|
|
520
|
+
xi_mkdir_p(dir);
|
|
521
|
+
char peer_path[256];
|
|
522
|
+
snprintf(peer_path, sizeof(peer_path), "%s/peer.xml", dir);
|
|
523
|
+
const char peer_xml[] = "<peer>from-dir</peer>";
|
|
524
|
+
FILE* fp = fopen(peer_path, "wb");
|
|
525
|
+
ASSERT_NE(fp, nullptr);
|
|
526
|
+
fwrite(peer_xml, 1, std::strlen(peer_xml), fp);
|
|
527
|
+
fclose(fp);
|
|
528
|
+
|
|
529
|
+
/* mid.xml lives in dir/ and includes peer.xml relatively */
|
|
530
|
+
char mid_path[256];
|
|
531
|
+
snprintf(mid_path, sizeof(mid_path), "%s/mid.xml", dir);
|
|
532
|
+
const char mid_xml[] =
|
|
533
|
+
"<mid xmlns:xi='http://www.w3.org/2001/XInclude'>"
|
|
534
|
+
" <xi:include href='peer.xml'/>"
|
|
535
|
+
"</mid>";
|
|
536
|
+
FILE* fm = fopen(mid_path, "wb");
|
|
537
|
+
ASSERT_NE(fm, nullptr);
|
|
538
|
+
fwrite(mid_xml, 1, std::strlen(mid_xml), fm);
|
|
539
|
+
fclose(fm);
|
|
540
|
+
|
|
541
|
+
const char xml[] =
|
|
542
|
+
"<root xmlns:xi='http://www.w3.org/2001/XInclude'>"
|
|
543
|
+
" <xi:include href='/tmp/leptris_xi_nested/mid.xml'/>"
|
|
544
|
+
"</root>";
|
|
545
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
546
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
547
|
+
ASSERT_NE(doc, nullptr);
|
|
548
|
+
|
|
549
|
+
EXPECT_EQ(leptris_xinclude_process(doc, nullptr), LEPTRIS_OK);
|
|
550
|
+
|
|
551
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
552
|
+
LeptrisElement mid = leptris_element_first_child_any(root);
|
|
553
|
+
ASSERT_NE(mid, nullptr);
|
|
554
|
+
LeptrisElement peer = leptris_element_first_child_any(mid);
|
|
555
|
+
ASSERT_NE(peer, nullptr);
|
|
556
|
+
EXPECT_STREQ(leptris_element_name(peer), "peer");
|
|
557
|
+
EXPECT_STREQ(leptris_element_text(peer), "from-dir");
|
|
558
|
+
|
|
559
|
+
leptris_document_free(doc);
|
|
560
|
+
remove(peer_path);
|
|
561
|
+
remove(mid_path);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// ---- TODO.assemble 04: resolver policy ---------------------------------
|
|
565
|
+
|
|
566
|
+
TEST(XIncludePolicy, NoNetworkRefusesRemoteWithFallback) {
|
|
567
|
+
const char xml[] =
|
|
568
|
+
"<root xmlns:xi='http://www.w3.org/2001/XInclude'>"
|
|
569
|
+
" <xi:include href='http://example.invalid/data.xml'>"
|
|
570
|
+
" <xi:fallback>offline</xi:fallback>"
|
|
571
|
+
" </xi:include>"
|
|
572
|
+
"</root>";
|
|
573
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
574
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
575
|
+
ASSERT_NE(doc, nullptr);
|
|
576
|
+
|
|
577
|
+
/* no_network defaults to 1 — the remote fetch is a resource
|
|
578
|
+
* error and the fallback applies. */
|
|
579
|
+
EXPECT_EQ(leptris_xinclude_process(doc, nullptr), LEPTRIS_OK);
|
|
580
|
+
|
|
581
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
582
|
+
ASSERT_NE(root, nullptr);
|
|
583
|
+
const char* rt = leptris_element_text(root);
|
|
584
|
+
ASSERT_NE(rt, nullptr);
|
|
585
|
+
EXPECT_NE(strstr(rt, "offline"), nullptr);
|
|
586
|
+
|
|
587
|
+
leptris_document_free(doc);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
TEST(XIncludePolicy, ResolverServesContent) {
|
|
591
|
+
const char xml[] =
|
|
592
|
+
"<root xmlns:xi='http://www.w3.org/2001/XInclude'>"
|
|
593
|
+
" <xi:include href='mem://thing'/>"
|
|
594
|
+
"</root>";
|
|
595
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
596
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
597
|
+
ASSERT_NE(doc, nullptr);
|
|
598
|
+
|
|
599
|
+
leptris_xinclude_opts opts;
|
|
600
|
+
memset(&opts, 0, sizeof(opts));
|
|
601
|
+
opts.no_network = 1;
|
|
602
|
+
opts.resolver = [](const char* uri, void* user, char** out_content,
|
|
603
|
+
size_t* out_len) -> int {
|
|
604
|
+
static const char inner_xml[] = "<served>by-resolver</served>";
|
|
605
|
+
(void)user;
|
|
606
|
+
if (strcmp(uri, "mem://thing") != 0) return 0;
|
|
607
|
+
size_t n = strlen(inner_xml) + 1;
|
|
608
|
+
*out_content = (char*)malloc(n);
|
|
609
|
+
if (!*out_content) return -1;
|
|
610
|
+
memcpy(*out_content, inner_xml, n);
|
|
611
|
+
*out_len = n - 1;
|
|
612
|
+
return 1;
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
EXPECT_EQ(leptris_xinclude_process_opts(doc, nullptr, &opts),
|
|
616
|
+
LEPTRIS_OK);
|
|
617
|
+
|
|
618
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
619
|
+
LeptrisElement served = leptris_element_first_child_any(root);
|
|
620
|
+
ASSERT_NE(served, nullptr);
|
|
621
|
+
EXPECT_STREQ(leptris_element_name(served), "served");
|
|
622
|
+
EXPECT_STREQ(leptris_element_text(served), "by-resolver");
|
|
623
|
+
|
|
624
|
+
leptris_document_free(doc);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
TEST(XIncludePolicy, CatalogMapsRemoteToLocal) {
|
|
628
|
+
/* A catalog entry rewrites a REMOTE name onto a local file —
|
|
629
|
+
* the network gate runs on the post-catalog URI, so the include
|
|
630
|
+
* resolves offline. */
|
|
631
|
+
const char target_xml[] = "<catalogued>local-copy</catalogued>";
|
|
632
|
+
const char* target_path = "/tmp/leptris_xi_cat_target.xml";
|
|
633
|
+
FILE* ft = fopen(target_path, "wb");
|
|
634
|
+
ASSERT_NE(ft, nullptr);
|
|
635
|
+
fwrite(target_xml, 1, std::strlen(target_xml), ft);
|
|
636
|
+
fclose(ft);
|
|
637
|
+
|
|
638
|
+
const char* cat_path = "/tmp/leptris_xi_catalog.xml";
|
|
639
|
+
const char cat_xml[] =
|
|
640
|
+
"<?xml version='1.0'?>"
|
|
641
|
+
"<catalog xmlns='urn:oasis:names:tc:entity:xmlns:xml:catalog'>"
|
|
642
|
+
" <uri name='http://example.invalid/catalogued.xml'"
|
|
643
|
+
" uri='/tmp/leptris_xi_cat_target.xml'/>"
|
|
644
|
+
"</catalog>";
|
|
645
|
+
FILE* fc = fopen(cat_path, "wb");
|
|
646
|
+
ASSERT_NE(fc, nullptr);
|
|
647
|
+
fwrite(cat_xml, 1, std::strlen(cat_xml), fc);
|
|
648
|
+
fclose(fc);
|
|
649
|
+
|
|
650
|
+
const char xml[] =
|
|
651
|
+
"<root xmlns:xi='http://www.w3.org/2001/XInclude'>"
|
|
652
|
+
" <xi:include href='http://example.invalid/catalogued.xml'/>"
|
|
653
|
+
"</root>";
|
|
654
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
655
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
656
|
+
ASSERT_NE(doc, nullptr);
|
|
657
|
+
|
|
658
|
+
leptris_xinclude_opts opts;
|
|
659
|
+
memset(&opts, 0, sizeof(opts));
|
|
660
|
+
opts.no_network = 1;
|
|
661
|
+
opts.catalog_path = cat_path;
|
|
662
|
+
|
|
663
|
+
EXPECT_EQ(leptris_xinclude_process_opts(doc, nullptr, &opts),
|
|
664
|
+
LEPTRIS_OK);
|
|
665
|
+
|
|
666
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
667
|
+
LeptrisElement got = leptris_element_first_child_any(root);
|
|
668
|
+
ASSERT_NE(got, nullptr);
|
|
669
|
+
EXPECT_STREQ(leptris_element_name(got), "catalogued");
|
|
670
|
+
EXPECT_STREQ(leptris_element_text(got), "local-copy");
|
|
671
|
+
|
|
672
|
+
leptris_document_free(doc);
|
|
673
|
+
remove(target_path);
|
|
674
|
+
remove(cat_path);
|
|
675
|
+
}
|
|
676
|
+
|
|
416
677
|
// ---- Phase 4: xpointer fragment selection (TODO 92) ------------------
|
|
417
678
|
|
|
418
679
|
TEST(XIncludeXpointer, SelectsFragmentByXPath) {
|
|
@@ -1149,6 +1149,175 @@ TEST(XPathResults, MixedNodesetKindsNamesValues) {
|
|
|
1149
1149
|
leptris_document_free(doc);
|
|
1150
1150
|
}
|
|
1151
1151
|
|
|
1152
|
+
TEST(XPathResults, NullContextIsDocumentNode) {
|
|
1153
|
+
/* leptris-ruby#458 root cause: a NULL context used to default to
|
|
1154
|
+
* the ROOT element; libxml2/Nokogiri document-level queries
|
|
1155
|
+
* evaluate against the DOCUMENT node — a relative name matches
|
|
1156
|
+
* the root element, and child::* yields exactly the root. */
|
|
1157
|
+
const char xml[] = "<r><a id='x'><b/></a></r>";
|
|
1158
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1159
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
1160
|
+
ASSERT_NE(doc, nullptr);
|
|
1161
|
+
|
|
1162
|
+
struct { const char* expr; int expect_count; } cases[] = {
|
|
1163
|
+
{ "r", 1 },
|
|
1164
|
+
{ "*", 1 },
|
|
1165
|
+
{ "node()", 1 },
|
|
1166
|
+
{ "a", 0 },
|
|
1167
|
+
{ "b", 0 },
|
|
1168
|
+
};
|
|
1169
|
+
for (auto& tc : cases) {
|
|
1170
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, nullptr, tc.expr);
|
|
1171
|
+
ASSERT_NE(r, (LeptrisXPathResult)0) << "eval failed: " << tc.expr;
|
|
1172
|
+
EXPECT_EQ(leptris_xpath_result_count(r), (size_t)tc.expect_count)
|
|
1173
|
+
<< tc.expr;
|
|
1174
|
+
if (tc.expect_count == 1) {
|
|
1175
|
+
EXPECT_EQ(leptris_xpath_result_node_kind(r, 0),
|
|
1176
|
+
LEPTRIS_XPATH_NODE_ELEMENT) << tc.expr;
|
|
1177
|
+
}
|
|
1178
|
+
leptris_xpath_result_free(r);
|
|
1179
|
+
}
|
|
1180
|
+
leptris_document_free(doc);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
TEST(XPathResults, DocumentContextDescendantAxes) {
|
|
1184
|
+
/* leptris-ruby#458 follow-up: from the document node (the
|
|
1185
|
+
* NULL-context default), descendant and descendant-or-self
|
|
1186
|
+
* axes must reach the whole tree — the root element is a
|
|
1187
|
+
* descendant of the document. The VM's relative descendant
|
|
1188
|
+
* opcodes skipped non-element inputs, so `.//a` and
|
|
1189
|
+
* descendant::a came back empty while `//a` worked. */
|
|
1190
|
+
const char xml[] = "<r><a id='x'><b/></a></r>";
|
|
1191
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1192
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
1193
|
+
ASSERT_NE(doc, nullptr);
|
|
1194
|
+
|
|
1195
|
+
struct { const char* expr; int expect_count; } cases[] = {
|
|
1196
|
+
{ "//a", 1 },
|
|
1197
|
+
{ ".//a", 1 },
|
|
1198
|
+
{ "descendant::a", 1 },
|
|
1199
|
+
{ "descendant-or-self::r", 1 },
|
|
1200
|
+
{ ".//b", 1 },
|
|
1201
|
+
{ "a", 0 },
|
|
1202
|
+
{ "descendant::z", 0 },
|
|
1203
|
+
};
|
|
1204
|
+
for (auto& tc : cases) {
|
|
1205
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, nullptr, tc.expr);
|
|
1206
|
+
ASSERT_NE(r, (LeptrisXPathResult)0) << "eval failed: " << tc.expr;
|
|
1207
|
+
EXPECT_EQ(leptris_xpath_result_count(r), (size_t)tc.expect_count)
|
|
1208
|
+
<< tc.expr;
|
|
1209
|
+
leptris_xpath_result_free(r);
|
|
1210
|
+
}
|
|
1211
|
+
leptris_document_free(doc);
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
TEST(XPathResults, XmlnsPrefixResolvesDefaultNamespace) {
|
|
1215
|
+
/* leptris-ruby#469: the reserved xmlns: prefix in an expression
|
|
1216
|
+
* resolves to the in-scope DEFAULT namespace of the evaluation
|
|
1217
|
+
* context — the libxml2/nokogiri idiom for default-namespaced
|
|
1218
|
+
* documents. Explicit bindings win first; unprefixed tests stay
|
|
1219
|
+
* spec-strict (no-namespace only). */
|
|
1220
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1221
|
+
const char xml[] =
|
|
1222
|
+
"<svgmap xmlns='http://example.org/doc'>"
|
|
1223
|
+
"<target href='a'/><sub xmlns='http://example.org/other'>"
|
|
1224
|
+
"<target href='b'/></sub></svgmap>";
|
|
1225
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
1226
|
+
ASSERT_NE(doc, nullptr);
|
|
1227
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
1228
|
+
ASSERT_NE(root, nullptr);
|
|
1229
|
+
|
|
1230
|
+
// Element context: child xmlns:target matches the default-ns child
|
|
1231
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, root, "./xmlns:target");
|
|
1232
|
+
ASSERT_NE(r, (LeptrisXPathResult)0);
|
|
1233
|
+
EXPECT_EQ(leptris_xpath_result_count(r), 1u);
|
|
1234
|
+
leptris_xpath_result_free(r);
|
|
1235
|
+
|
|
1236
|
+
// Absolute form from document level (the nokogiri idiom spells
|
|
1237
|
+
// every step xmlns:)
|
|
1238
|
+
r = leptris_xpath_eval(doc, nullptr, "//xmlns:svgmap/xmlns:target");
|
|
1239
|
+
ASSERT_NE(r, (LeptrisXPathResult)0);
|
|
1240
|
+
EXPECT_EQ(leptris_xpath_result_count(r), 1u);
|
|
1241
|
+
leptris_xpath_result_free(r);
|
|
1242
|
+
|
|
1243
|
+
// The INNER default declaration wins inside <sub>: its target
|
|
1244
|
+
// child is in the 'other' namespace, not the root's default.
|
|
1245
|
+
// (And xmlns:sub from the root correctly does NOT match — the
|
|
1246
|
+
// element carrying xmlns='other' is in 'other'.)
|
|
1247
|
+
r = leptris_xpath_eval(doc, root, "./xmlns:sub");
|
|
1248
|
+
ASSERT_NE(r, (LeptrisXPathResult)0);
|
|
1249
|
+
EXPECT_EQ(leptris_xpath_result_count(r), 0u);
|
|
1250
|
+
leptris_xpath_result_free(r);
|
|
1251
|
+
r = leptris_xpath_eval(doc, root, ".//xmlns:target");
|
|
1252
|
+
ASSERT_NE(r, (LeptrisXPathResult)0);
|
|
1253
|
+
EXPECT_EQ(leptris_xpath_result_count(r), 1u);
|
|
1254
|
+
leptris_xpath_result_free(r);
|
|
1255
|
+
|
|
1256
|
+
// Unprefixed name tests stay spec-strict: no-namespace only
|
|
1257
|
+
r = leptris_xpath_eval(doc, root, "./target");
|
|
1258
|
+
ASSERT_NE(r, (LeptrisXPathResult)0);
|
|
1259
|
+
EXPECT_EQ(leptris_xpath_result_count(r), 0u);
|
|
1260
|
+
leptris_xpath_result_free(r);
|
|
1261
|
+
|
|
1262
|
+
// An explicit binding overrides the quirk
|
|
1263
|
+
LeptrisXPathNsSet ns = leptris_xpath_ns_set_new();
|
|
1264
|
+
ASSERT_NE(ns, (LeptrisXPathNsSet)0);
|
|
1265
|
+
ASSERT_EQ(leptris_xpath_ns_set_add(ns, "x", "http://example.org/doc"),
|
|
1266
|
+
LEPTRIS_OK);
|
|
1267
|
+
r = leptris_xpath_eval_ns(doc, root, "./x:target", ns);
|
|
1268
|
+
ASSERT_NE(r, (LeptrisXPathResult)0);
|
|
1269
|
+
EXPECT_EQ(leptris_xpath_result_count(r), 1u);
|
|
1270
|
+
leptris_xpath_result_free(r);
|
|
1271
|
+
leptris_xpath_ns_set_free(ns);
|
|
1272
|
+
|
|
1273
|
+
// No default declaration in scope: xmlns: matches nothing
|
|
1274
|
+
LeptrisDocument plain = leptris_parse_string("<r><t/></r>", 11, &st);
|
|
1275
|
+
ASSERT_NE(plain, nullptr);
|
|
1276
|
+
r = leptris_xpath_eval(plain, nullptr, "//xmlns:t");
|
|
1277
|
+
ASSERT_NE(r, (LeptrisXPathResult)0);
|
|
1278
|
+
EXPECT_EQ(leptris_xpath_result_count(r), 0u);
|
|
1279
|
+
leptris_xpath_result_free(r);
|
|
1280
|
+
leptris_document_free(plain);
|
|
1281
|
+
|
|
1282
|
+
leptris_document_free(doc);
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
TEST(XPathResults, AttributeTerminalPathShapes) {
|
|
1286
|
+
/* leptris-ruby#458: the final step being an ATTRIBUTE works for
|
|
1287
|
+
* //a/@id and //@id but must work for every relative-path shape
|
|
1288
|
+
* too: r/a/@id (silent empty today) and the filter-expr form
|
|
1289
|
+
* //*[...]/@id (engine grammar: "Unexpected token after
|
|
1290
|
+
* expression: SLASH"). */
|
|
1291
|
+
const char xml[] = "<r><a id='x'><b/></a></r>";
|
|
1292
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1293
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
1294
|
+
ASSERT_NE(doc, nullptr);
|
|
1295
|
+
|
|
1296
|
+
struct { const char* expr; int expect_count; } cases[] = {
|
|
1297
|
+
{ "//a/@id", 1 },
|
|
1298
|
+
{ "//@id", 1 },
|
|
1299
|
+
{ "r/a/@id", 1 },
|
|
1300
|
+
{ "//*[local-name()='a']/@id", 1 },
|
|
1301
|
+
{ "./@id", 0 },
|
|
1302
|
+
};
|
|
1303
|
+
for (auto& tc : cases) {
|
|
1304
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, nullptr, tc.expr);
|
|
1305
|
+
ASSERT_NE(r, (LeptrisXPathResult)0)
|
|
1306
|
+
<< "eval failed: " << tc.expr;
|
|
1307
|
+
EXPECT_EQ(leptris_xpath_result_count(r),
|
|
1308
|
+
(size_t)tc.expect_count)
|
|
1309
|
+
<< tc.expr;
|
|
1310
|
+
if (tc.expect_count == 1) {
|
|
1311
|
+
EXPECT_EQ(leptris_xpath_result_node_kind(r, 0),
|
|
1312
|
+
LEPTRIS_XPATH_NODE_ATTRIBUTE) << tc.expr;
|
|
1313
|
+
EXPECT_STREQ(leptris_xpath_result_node_value(r, 0), "x")
|
|
1314
|
+
<< tc.expr;
|
|
1315
|
+
}
|
|
1316
|
+
leptris_xpath_result_free(r);
|
|
1317
|
+
}
|
|
1318
|
+
leptris_document_free(doc);
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1152
1321
|
TEST(XPathResults, MixedNodesetAttributeNameValue) {
|
|
1153
1322
|
const char xml[] = "<r><a id='x1'>t</a></r>";
|
|
1154
1323
|
LeptrisStatus st = LEPTRIS_OK;
|
|
@@ -216,7 +216,14 @@ TEST(XPathConformanceBoolean, TrueAndFalseAreConstants) {
|
|
|
216
216
|
|
|
217
217
|
TEST(XPathConformanceBoolean, LangMatchesLanguage) {
|
|
218
218
|
auto doc = Parse("<r xml:lang='en'><a/></r>");
|
|
219
|
-
|
|
219
|
+
// lang() inspects the context node's ancestors — evaluate on the
|
|
220
|
+
// root element (a document-node context has no xml:lang ancestor,
|
|
221
|
+
// the doc-level default from the XPathResults parity spec).
|
|
222
|
+
LeptrisXPathResult r =
|
|
223
|
+
leptris_xpath_eval(doc, leptris_document_root(doc), "lang('en')");
|
|
224
|
+
ASSERT_NE(r, nullptr);
|
|
225
|
+
EXPECT_TRUE(leptris_xpath_result_boolean(r));
|
|
226
|
+
leptris_xpath_result_free(r);
|
|
220
227
|
leptris_document_free(doc);
|
|
221
228
|
}
|
|
222
229
|
|
|
@@ -143,17 +143,21 @@ TEST(Libxml2Corpus, EveryFixtureCompilesOrFailsCleanly) {
|
|
|
143
143
|
}
|
|
144
144
|
EXPECT_GE(ok + failed, 160u) << "fixture set shrank";
|
|
145
145
|
// Compile floor: was 163/163 when compile was unconditional —
|
|
146
|
-
// the structure
|
|
147
|
-
// schema-error fixtures
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
// delta
|
|
152
|
-
//
|
|
153
|
-
//
|
|
146
|
+
// the structure checks (#1691) now legitimately reject the
|
|
147
|
+
// schema-error fixtures (slices 1-3: src-attribute/src-element
|
|
148
|
+
// clauses, occurrence ordering, include-tns, xsi/xmlns
|
|
149
|
+
// reservations). The floor is the CROSS-PLATFORM minimum:
|
|
150
|
+
// Linux (case-sensitive fs) resolves 4 more fixtures'
|
|
151
|
+
// schemaLocations than macOS (delta tracked in #1691). The
|
|
152
|
+
// differential expectations live in XsdConformance
|
|
153
|
+
// (MANIFEST.tsv). Monotonic.
|
|
154
154
|
RecordProperty("ok", std::to_string(ok));
|
|
155
155
|
RecordProperty("failed", std::to_string(failed));
|
|
156
|
-
|
|
156
|
+
// 150 -> 147 (slice 4: transitive include-tns, content-type
|
|
157
|
+
// mismatch, attribute-wildcard restriction) -> 142 (slice 5:
|
|
158
|
+
// ref QNames must resolve) -> 139 (slice 6: UPA —
|
|
159
|
+
// non-deterministic content models rejected).
|
|
160
|
+
EXPECT_GE(ok, 139u) << "compile-success floor regressed";
|
|
157
161
|
}
|
|
158
162
|
|
|
159
163
|
} // namespace
|
|
@@ -1942,6 +1946,119 @@ TEST(XsdErrorContext, ContentModelErrorCarriesPosition) {
|
|
|
1942
1946
|
|
|
1943
1947
|
} // namespace
|
|
1944
1948
|
|
|
1949
|
+
/* ---- #1691 slice 4: oracle-rejected schemas the engine must refuse
|
|
1950
|
+
* to compile. File-based: the shapes need on-disk include graphs and
|
|
1951
|
+
* global-declaration resolution. Each fixture is a measured
|
|
1952
|
+
* schema-error row of the differential lane. */
|
|
1953
|
+
TEST(XsdConformanceClauses, TransitiveIncludeTnsMismatchRejected) {
|
|
1954
|
+
/* 582906-2: the root IMPORTS prog1/prog2 (cross-namespace
|
|
1955
|
+
* imports are legal); the src-include.1 violation lives one hop
|
|
1956
|
+
* deeper — prog1/prog2 INCLUDE common, whose targetNamespace
|
|
1957
|
+
* differs from THEIRS. The include-tns check must recurse into
|
|
1958
|
+
* every loaded document, not just the root. */
|
|
1959
|
+
LeptrisStatus st = (LeptrisStatus)0;
|
|
1960
|
+
std::string p = std::string(LEPTRIS_XSD_CASES_DIR) + "/582906-2_0.xsd";
|
|
1961
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(p.c_str(), &st);
|
|
1962
|
+
/* failure contract: an error-carrying handle + non-OK status */
|
|
1963
|
+
EXPECT_NE(st, LEPTRIS_OK)
|
|
1964
|
+
<< "src-include.1 must fire transitively";
|
|
1965
|
+
EXPECT_NE(leptris_xsd_error(s), nullptr);
|
|
1966
|
+
leptris_xsd_free(s);
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
TEST(XsdConformanceClauses, ExtensionContentTypeMismatchRejected) {
|
|
1970
|
+
/* issue491 (cos-ct-derived-ok, libxml2: "the content type of
|
|
1971
|
+
* both, the type and its base type, must either mixed or
|
|
1972
|
+
* element-only"): complexContent extension of a simpleContent
|
|
1973
|
+
* base. */
|
|
1974
|
+
LeptrisStatus st = (LeptrisStatus)0;
|
|
1975
|
+
std::string p = std::string(LEPTRIS_XSD_CASES_DIR) + "/issue491_0.xsd";
|
|
1976
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(p.c_str(), &st);
|
|
1977
|
+
EXPECT_NE(st, LEPTRIS_OK)
|
|
1978
|
+
<< "content-type mismatch on extension must be rejected";
|
|
1979
|
+
EXPECT_NE(leptris_xsd_error(s), nullptr);
|
|
1980
|
+
leptris_xsd_free(s);
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
TEST(XsdConformanceClauses, RestrictionWildcardNeedsBaseWildcard) {
|
|
1984
|
+
/* derivation-ok-restriction-4-1: a restricted complex type with
|
|
1985
|
+
* an attribute wildcard requires the base type to carry one
|
|
1986
|
+
* (and the derived wildcard must be a subset). */
|
|
1987
|
+
LeptrisStatus st = (LeptrisStatus)0;
|
|
1988
|
+
std::string p = std::string(LEPTRIS_XSD_CASES_DIR) +
|
|
1989
|
+
"/derivation-ok-restriction-4-1-err_0.xsd";
|
|
1990
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(p.c_str(), &st);
|
|
1991
|
+
EXPECT_NE(st, LEPTRIS_OK)
|
|
1992
|
+
<< "attribute-wildcard restriction without a base wildcard "
|
|
1993
|
+
"must be rejected";
|
|
1994
|
+
EXPECT_NE(leptris_xsd_error(s), nullptr);
|
|
1995
|
+
leptris_xsd_free(s);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
TEST(XsdConformanceClauses, NonDeterministicSequenceRejected) {
|
|
1999
|
+
/* deter0_0: (odd,even)* followed by odd? — after the loop, the
|
|
2000
|
+
* trailing odd? collides with the loop restart. UPA violation. */
|
|
2001
|
+
LeptrisStatus st = (LeptrisStatus)0;
|
|
2002
|
+
std::string p = std::string(LEPTRIS_XSD_CASES_DIR) + "/deter0_0.xsd";
|
|
2003
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(p.c_str(), &st);
|
|
2004
|
+
EXPECT_NE(st, LEPTRIS_OK) << "UPA violation must be rejected";
|
|
2005
|
+
leptris_xsd_free(s);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
TEST(XsdConformanceClauses, WildcardChoiceOverlapRejected) {
|
|
2009
|
+
/* any4_0: a choice branch wildcard whose namespace covers the
|
|
2010
|
+
* other branch's explicit element — ambiguous. */
|
|
2011
|
+
LeptrisStatus st = (LeptrisStatus)0;
|
|
2012
|
+
std::string p = std::string(LEPTRIS_XSD_CASES_DIR) + "/any4_0.xsd";
|
|
2013
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(p.c_str(), &st);
|
|
2014
|
+
EXPECT_NE(st, LEPTRIS_OK) << "ambiguous wildcard choice must be rejected";
|
|
2015
|
+
leptris_xsd_free(s);
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
TEST(XsdConformanceClauses, DeterministicRepeatStillLoads) {
|
|
2019
|
+
/* (a, a) is DETERMINISTIC (both required); the UPA check must
|
|
2020
|
+
* not fire on required adjacency, and ##other must not cover
|
|
2021
|
+
* targetNamespace elements (any5_1's (boo, other*, boo)). */
|
|
2022
|
+
LeptrisStatus st = (LeptrisStatus)0;
|
|
2023
|
+
std::string p =
|
|
2024
|
+
std::string(LEPTRIS_XSD_CASES_DIR) + "/seq-dubl-elem1_0.xsd";
|
|
2025
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(p.c_str(), &st);
|
|
2026
|
+
EXPECT_EQ(st, LEPTRIS_OK);
|
|
2027
|
+
leptris_xsd_free(s);
|
|
2028
|
+
std::string p2 = std::string(LEPTRIS_XSD_CASES_DIR) + "/any5_1.xsd";
|
|
2029
|
+
LeptrisXsdSchema s2 = leptris_xsd_compile_file(p2.c_str(), &st);
|
|
2030
|
+
EXPECT_EQ(st, LEPTRIS_OK);
|
|
2031
|
+
leptris_xsd_free(s2);
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
TEST(XsdConformanceClauses, UnresolvableRefQNameRejected) {
|
|
2035
|
+
/* import1_0 (src-element.2): an xs:element/@ref whose QName
|
|
2036
|
+
* resolves to no declaration (the import target file is
|
|
2037
|
+
* missing) is a schema-load error. Resolution is by
|
|
2038
|
+
* DECLARATION across the include/import graph (chameleon
|
|
2039
|
+
* includes adopt the includer's namespace); namespace-only
|
|
2040
|
+
* imports and missing files provide nothing. */
|
|
2041
|
+
LeptrisStatus st = (LeptrisStatus)0;
|
|
2042
|
+
std::string p = std::string(LEPTRIS_XSD_CASES_DIR) + "/import1_0.xsd";
|
|
2043
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(p.c_str(), &st);
|
|
2044
|
+
EXPECT_NE(st, LEPTRIS_OK)
|
|
2045
|
+
<< "an unresolved ref QName must be rejected";
|
|
2046
|
+
EXPECT_NE(leptris_xsd_error(s), nullptr);
|
|
2047
|
+
leptris_xsd_free(s);
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
TEST(XsdConformanceClauses, ChameleonIncludeDeclaresResolve) {
|
|
2051
|
+
/* The counterpart contract: declarations inside a chameleon
|
|
2052
|
+
* include (no targetNamespace) resolve under the INCLUDING
|
|
2053
|
+
* schema's namespace — include1_0's ref="foo:bar" resolves to
|
|
2054
|
+
* the .inc's element bar, and the schema must load. */
|
|
2055
|
+
LeptrisStatus st = (LeptrisStatus)0;
|
|
2056
|
+
std::string p = std::string(LEPTRIS_XSD_CASES_DIR) + "/include1_0.xsd";
|
|
2057
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(p.c_str(), &st);
|
|
2058
|
+
EXPECT_EQ(st, LEPTRIS_OK);
|
|
2059
|
+
leptris_xsd_free(s);
|
|
2060
|
+
}
|
|
2061
|
+
|
|
1945
2062
|
/* ---- #1075: the differential conformance lane ---------------------
|
|
1946
2063
|
*
|
|
1947
2064
|
* MANIFEST.tsv is generated by scripts/gen_xsd_manifest.py: the
|
|
@@ -2016,10 +2133,10 @@ TEST(XsdConformance, ManifestExpectationsMatchOracle) {
|
|
|
2016
2133
|
* schema-constraint gate is laxer than the oracle's; see the
|
|
2017
2134
|
* divergence tracker). Monotonically rising — each fix here
|
|
2018
2135
|
* retires oracle divergences wholesale. */
|
|
2019
|
-
EXPECT_GE(pass,
|
|
2136
|
+
EXPECT_GE(pass, 898) << "conformance floor regressed";
|
|
2020
2137
|
EXPECT_GE(pass_valid, 151);
|
|
2021
2138
|
EXPECT_GE(pass_invalid, 618);
|
|
2022
|
-
EXPECT_GE(pass_schema_error,
|
|
2139
|
+
EXPECT_GE(pass_schema_error, 129);
|
|
2023
2140
|
RecordProperty("pass_valid", std::to_string(pass_valid));
|
|
2024
2141
|
RecordProperty("pass_invalid", std::to_string(pass_invalid));
|
|
2025
2142
|
RecordProperty("pass_schema_error", std::to_string(pass_schema_error));
|
|
@@ -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.359",
|
|
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",
|