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
|
@@ -158,18 +158,30 @@ static int any_ns_matches(XsdCm* any, const char* uri,
|
|
|
158
158
|
if (strcmp(f, "##other") == 0)
|
|
159
159
|
return uri != NULL &&
|
|
160
160
|
!(target_ns && strcmp(uri, target_ns) == 0);
|
|
161
|
-
/*
|
|
161
|
+
/* whitespace-separated URI list (+##local): the attribute value
|
|
162
|
+
* may span lines (pretty-printed schemas indent the continuation),
|
|
163
|
+
* so token separators are all XML whitespace, not just spaces. */
|
|
162
164
|
const char* p = f;
|
|
163
165
|
while (*p) {
|
|
164
|
-
while (*p == ' ') p++;
|
|
166
|
+
while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') p++;
|
|
165
167
|
const char* start = p;
|
|
166
|
-
while (*p && *p != ' ') p++;
|
|
168
|
+
while (*p && *p != ' ' && *p != '\t' && *p != '\n' && *p != '\r') p++;
|
|
167
169
|
size_t len = (size_t)(p - start);
|
|
168
170
|
if (len == 0) break;
|
|
169
171
|
if (strncmp(start, "##local", len) == 0 && len == 7) {
|
|
170
172
|
if (uri == NULL) return 1;
|
|
171
173
|
continue;
|
|
172
174
|
}
|
|
175
|
+
if (strncmp(start, "##targetNamespace", len) == 0 && len == 17) {
|
|
176
|
+
if (target_ns && uri && strcmp(uri, target_ns) == 0) return 1;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (strncmp(start, "##other", len) == 0 && len == 7) {
|
|
180
|
+
if (uri != NULL &&
|
|
181
|
+
!(target_ns && strcmp(uri, target_ns) == 0))
|
|
182
|
+
return 1;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
173
185
|
if (uri && strlen(uri) == len && strncmp(start, uri, len) == 0)
|
|
174
186
|
return 1;
|
|
175
187
|
}
|
|
@@ -399,6 +399,21 @@ static int any_attr_matches(const char* grammar, const char* uri,
|
|
|
399
399
|
const char* start = p;
|
|
400
400
|
while (*p && *p != ' ' && *p != '\t') p++;
|
|
401
401
|
size_t len = (size_t)(p - start);
|
|
402
|
+
if (len == 7 && strncmp(start, "##local", 7) == 0) {
|
|
403
|
+
if (uri == NULL) return 1;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (len == 17 &&
|
|
407
|
+
strncmp(start, "##targetNamespace", 17) == 0) {
|
|
408
|
+
if (uri && target_ns && strcmp(uri, target_ns) == 0)
|
|
409
|
+
return 1;
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (len == 7 && strncmp(start, "##other", 7) == 0) {
|
|
413
|
+
if (uri && target_ns && strcmp(uri, target_ns) != 0)
|
|
414
|
+
return 1;
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
402
417
|
if (uri && strlen(uri) == len && strncmp(uri, start, len) == 0)
|
|
403
418
|
return 1;
|
|
404
419
|
}
|
|
@@ -457,15 +472,18 @@ static void validate_attributes(struct xsd_validator* v,
|
|
|
457
472
|
strcmp(a->name, qn) == 0)
|
|
458
473
|
declared = 1;
|
|
459
474
|
if (declared) continue;
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
475
|
+
/* namespace of the attribute: engine-side attributes
|
|
476
|
+
* carry their uri through the expanded form */
|
|
477
|
+
const char* auri = leptris_attribute_namespace_uri(at);
|
|
478
|
+
/* extension union: an attribute is allowed when it matches the
|
|
479
|
+
* derived type's wildcard OR the base type's (the spec's
|
|
480
|
+
* attribute-wildcard union; #1691 anyAttr-derive family) */
|
|
481
|
+
if ((ta->any_attr_ns &&
|
|
482
|
+
any_attr_matches(ta->any_attr_ns, auri, xsd_target_ns(s))) ||
|
|
483
|
+
(ta->any_attr_base_ns &&
|
|
484
|
+
any_attr_matches(ta->any_attr_base_ns, auri,
|
|
485
|
+
xsd_target_ns(s))))
|
|
486
|
+
continue;
|
|
469
487
|
verrf_at(v, elem, "attribute", local,
|
|
470
488
|
"not declared (strict)");
|
|
471
489
|
}
|
|
@@ -197,6 +197,7 @@ typedef struct xsd_type_attrs {
|
|
|
197
197
|
char* type_name;
|
|
198
198
|
char* ns; /* leptris-ruby#440: declaring schema's tns */
|
|
199
199
|
char* any_attr_ns; /* xs:anyAttribute grammar (NULL = absent) */
|
|
200
|
+
char* any_attr_base_ns; /* extension: the base type's wildcard (union) */
|
|
200
201
|
XsdAttrDecl* attrs;
|
|
201
202
|
struct xsd_type_attrs* next;
|
|
202
203
|
} XsdTypeAttrs;
|
|
@@ -319,24 +319,58 @@ TEST(CliValidate, SvrlReportPrints) {
|
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
TEST(CliValidate, RngRound) {
|
|
322
|
-
write_file("
|
|
322
|
+
write_file("leptris_cli_val_rng.rng",
|
|
323
323
|
"<element name='r'"
|
|
324
324
|
" xmlns='http://relaxng.org/ns/structure/1.0'>"
|
|
325
325
|
"<oneOrMore><element name='item'>"
|
|
326
326
|
"<attribute name='n'/></element></oneOrMore>"
|
|
327
327
|
"</element>");
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
328
|
+
/* per-test filenames: these tests run CONCURRENTLY under ctest
|
|
329
|
+
* -j4 in the same cwd, and a same-path different-content write
|
|
330
|
+
* from a sibling test races the CLI read (the flake: RngRound
|
|
331
|
+
* validating MissingSchemaIsIoError's <r/>). */
|
|
332
|
+
write_file("leptris_cli_val_rng_ok.xml", "<r><item n='2'/></r>");
|
|
333
|
+
auto r = run_cli({"validate", "--rng", "leptris_cli_val_rng.rng",
|
|
334
|
+
"leptris_cli_val_rng_ok.xml"});
|
|
331
335
|
EXPECT_EQ(r.exit_code, 0) << "stderr: " << r.err;
|
|
332
336
|
EXPECT_NE(r.out.find("rng: valid"), std::string::npos);
|
|
333
337
|
}
|
|
334
338
|
|
|
339
|
+
TEST(CliValidate, RngReportCarriesAllDiagnostics) {
|
|
340
|
+
/* #1704: a misplaced element that ALSO carries an invalid
|
|
341
|
+
* attribute reports BOTH diagnostics (Jing parity), plus the
|
|
342
|
+
* incompleteness note — the CLI prints the whole report. */
|
|
343
|
+
write_file("leptris_cli_val_rng_both.rng",
|
|
344
|
+
"<grammar ns='https://example.org/s'"
|
|
345
|
+
" xmlns='http://relaxng.org/ns/structure/1.0'>"
|
|
346
|
+
"<start><element name='doc'>"
|
|
347
|
+
"<element name='ok'><text/></element>"
|
|
348
|
+
"</element></start>"
|
|
349
|
+
"<define name='p'><optional>"
|
|
350
|
+
"<attribute name='align'><choice>"
|
|
351
|
+
"<value>left</value><value>right</value>"
|
|
352
|
+
"</choice></attribute></optional><text/></define>"
|
|
353
|
+
"</grammar>");
|
|
354
|
+
write_file("leptris_cli_val_rng_both.xml",
|
|
355
|
+
"<doc xmlns='https://example.org/s'>"
|
|
356
|
+
"<p align='mid-air'>t</p></doc>");
|
|
357
|
+
auto r = run_cli({"validate", "--rng", "leptris_cli_val_rng_both.rng",
|
|
358
|
+
"leptris_cli_val_rng_both.xml"});
|
|
359
|
+
EXPECT_NE(r.exit_code, 0) << "stderr: " << r.err;
|
|
360
|
+
EXPECT_NE(r.out.find("rng: invalid"), std::string::npos);
|
|
361
|
+
EXPECT_NE(r.out.find("element \"p\" not allowed"),
|
|
362
|
+
std::string::npos)
|
|
363
|
+
<< r.out;
|
|
364
|
+
EXPECT_NE(r.out.find("value of attribute \"align\" is invalid"),
|
|
365
|
+
std::string::npos)
|
|
366
|
+
<< r.out;
|
|
367
|
+
}
|
|
368
|
+
|
|
335
369
|
TEST(CliValidate, MissingSchemaIsIoError) {
|
|
336
|
-
write_file("
|
|
370
|
+
write_file("leptris_cli_val_schmissing_ok.xml", "<r/>");
|
|
337
371
|
auto r = run_cli({"validate", "--schematron",
|
|
338
372
|
"leptris_cli_no_such.sch",
|
|
339
|
-
"
|
|
373
|
+
"leptris_cli_val_schmissing_ok.xml"});
|
|
340
374
|
EXPECT_EQ((r.exit_code >> 8) & 0xFF, 3)
|
|
341
375
|
<< "stderr: " << r.err;
|
|
342
376
|
}
|
|
@@ -522,32 +556,34 @@ TEST(CliDiff, JsonOpsListed) {
|
|
|
522
556
|
#if !defined(_WIN32)
|
|
523
557
|
|
|
524
558
|
TEST(CliValidate, DtdValidPasses) {
|
|
525
|
-
write_file("
|
|
559
|
+
write_file("leptris_cli_val_dtd_ok.dtd",
|
|
526
560
|
"<!ELEMENT r (item+)>\n"
|
|
527
561
|
"<!ELEMENT item EMPTY>\n"
|
|
528
562
|
"<!ATTLIST item n CDATA #IMPLIED>\n");
|
|
529
|
-
write_file("
|
|
530
|
-
auto r = run_cli({"validate", "--dtd",
|
|
531
|
-
"
|
|
563
|
+
write_file("leptris_cli_val_dtd_ok.xml", "<r><item/><item/></r>");
|
|
564
|
+
auto r = run_cli({"validate", "--dtd",
|
|
565
|
+
"leptris_cli_val_dtd_ok.dtd",
|
|
566
|
+
"leptris_cli_val_dtd_ok.xml"});
|
|
532
567
|
EXPECT_EQ(r.exit_code, 0) << "stderr: " << r.err;
|
|
533
568
|
EXPECT_NE(r.out.find("dtd: valid"), std::string::npos);
|
|
534
569
|
}
|
|
535
570
|
|
|
536
571
|
TEST(CliValidate, DtdInvalidFails) {
|
|
537
|
-
write_file("
|
|
572
|
+
write_file("leptris_cli_val_dtd_bad.dtd",
|
|
538
573
|
"<!ELEMENT r (item+)>\n"
|
|
539
574
|
"<!ELEMENT item EMPTY>\n");
|
|
540
575
|
write_file("leptris_cli_val_bad2.xml", "<r><item>x</item></r>");
|
|
541
|
-
auto r = run_cli({"validate", "--dtd",
|
|
576
|
+
auto r = run_cli({"validate", "--dtd",
|
|
577
|
+
"leptris_cli_val_dtd_bad.dtd",
|
|
542
578
|
"leptris_cli_val_bad2.xml"});
|
|
543
579
|
EXPECT_EQ((r.exit_code >> 8) & 0xFF, 1) << "stderr: " << r.err;
|
|
544
580
|
EXPECT_NE(r.out.find("dtd: invalid"), std::string::npos);
|
|
545
581
|
}
|
|
546
582
|
|
|
547
583
|
TEST(CliValidate, MissingDtdIsIoError) {
|
|
548
|
-
write_file("
|
|
584
|
+
write_file("leptris_cli_val_dtdmissing_ok.xml", "<r/>");
|
|
549
585
|
auto r = run_cli({"validate", "--dtd", "leptris_cli_no_such.dtd",
|
|
550
|
-
"
|
|
586
|
+
"leptris_cli_val_dtdmissing_ok.xml"});
|
|
551
587
|
EXPECT_EQ((r.exit_code >> 8) & 0xFF, 3) << "stderr: " << r.err;
|
|
552
588
|
}
|
|
553
589
|
|
|
@@ -288,7 +288,7 @@ TEST(DtdValidate, UniqueIdsAreValid) {
|
|
|
288
288
|
ASSERT_NE(doc, nullptr);
|
|
289
289
|
|
|
290
290
|
const char dtd_text[] =
|
|
291
|
-
"<!ELEMENT root (a|b)
|
|
291
|
+
"<!ELEMENT root (a|b)*>"
|
|
292
292
|
"<!ELEMENT a EMPTY>"
|
|
293
293
|
"<!ELEMENT b EMPTY>"
|
|
294
294
|
"<!ATTLIST a id ID #IMPLIED>"
|
|
@@ -315,7 +315,7 @@ TEST(DtdValidate, DuplicateIdIsInvalid) {
|
|
|
315
315
|
ASSERT_NE(doc, nullptr);
|
|
316
316
|
|
|
317
317
|
const char dtd_text[] =
|
|
318
|
-
"<!ELEMENT root (a|b)
|
|
318
|
+
"<!ELEMENT root (a|b)*>"
|
|
319
319
|
"<!ELEMENT a EMPTY>"
|
|
320
320
|
"<!ELEMENT b EMPTY>"
|
|
321
321
|
"<!ATTLIST a id ID #IMPLIED>"
|
|
@@ -343,7 +343,7 @@ TEST(DtdValidate, IdrefResolvesIsValid) {
|
|
|
343
343
|
ASSERT_NE(doc, nullptr);
|
|
344
344
|
|
|
345
345
|
const char dtd_text[] =
|
|
346
|
-
"<!ELEMENT root (a|b)
|
|
346
|
+
"<!ELEMENT root (a|b)*>"
|
|
347
347
|
"<!ELEMENT a EMPTY>"
|
|
348
348
|
"<!ELEMENT b EMPTY>"
|
|
349
349
|
"<!ATTLIST a id ID #IMPLIED>"
|
|
@@ -370,7 +370,7 @@ TEST(DtdValidate, IdrefUnresolvedIsInvalid) {
|
|
|
370
370
|
ASSERT_NE(doc, nullptr);
|
|
371
371
|
|
|
372
372
|
const char dtd_text[] =
|
|
373
|
-
"<!ELEMENT root (a|b)
|
|
373
|
+
"<!ELEMENT root (a|b)*>"
|
|
374
374
|
"<!ELEMENT a EMPTY>"
|
|
375
375
|
"<!ELEMENT b EMPTY>"
|
|
376
376
|
"<!ATTLIST a id ID #IMPLIED>"
|
|
@@ -1317,6 +1317,82 @@ TEST(DtdValidate, ExternalPEWithoutLoaderIsSkippedLeniently) {
|
|
|
1317
1317
|
|
|
1318
1318
|
// ---- #1211: the documented NULL-on-error contract ----
|
|
1319
1319
|
|
|
1320
|
+
/* ---- TODO.hygiene/02 closeout: Phase 8 residuals -------------------
|
|
1321
|
+
*
|
|
1322
|
+
* Behavioral gaps the probe run surfaced:
|
|
1323
|
+
* - a MIXED content model delivered through a parameter entity
|
|
1324
|
+
* ((#PCDATA|b)* via %pe;) validates as if #PCDATA were
|
|
1325
|
+
* required-once — the * through the PE doesn't apply;
|
|
1326
|
+
* - a nested parenthesized choice-with-sequence ((a|b,c))+ fails
|
|
1327
|
+
* to PARSE at all. */
|
|
1328
|
+
|
|
1329
|
+
static LeptrisDTD* parse_dtd_ok(const char* text) {
|
|
1330
|
+
LeptrisDTD* d = leptris_dtd_parse(text, std::strlen(text));
|
|
1331
|
+
EXPECT_NE(d, nullptr) << text;
|
|
1332
|
+
return d;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
static int validates(const char* dtd_text, const char* xml) {
|
|
1336
|
+
LeptrisDTD* d = parse_dtd_ok(dtd_text);
|
|
1337
|
+
if (!d) return -1;
|
|
1338
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1339
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
1340
|
+
if (!doc) {
|
|
1341
|
+
leptris_dtd_free(d);
|
|
1342
|
+
return -2;
|
|
1343
|
+
}
|
|
1344
|
+
LeptrisDTDError err = {0};
|
|
1345
|
+
int rc = leptris_dtd_validate(doc, d, &err);
|
|
1346
|
+
leptris_dtd_error_free(&err);
|
|
1347
|
+
leptris_document_free(doc);
|
|
1348
|
+
leptris_dtd_free(d);
|
|
1349
|
+
return rc;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
TEST(DtdPhase8, MixedModelThroughParameterEntity) {
|
|
1353
|
+
/* #PCDATA|b)* delivered via %mix; must behave exactly like the
|
|
1354
|
+
* inline spelling: mixed content, b elements interleaved. */
|
|
1355
|
+
EXPECT_EQ(validates(
|
|
1356
|
+
"<!ELEMENT doc (item)*>\n"
|
|
1357
|
+
"<!ENTITY % mix \"(#PCDATA|b)*\">\n"
|
|
1358
|
+
"<!ELEMENT item %mix;>\n",
|
|
1359
|
+
"<doc><item>x<b/>y</item></doc>"), 1);
|
|
1360
|
+
EXPECT_EQ(validates(
|
|
1361
|
+
"<!ELEMENT doc (item)*>\n"
|
|
1362
|
+
"<!ENTITY % mix \"(#PCDATA|b)*\">\n"
|
|
1363
|
+
"<!ELEMENT item %mix;>\n",
|
|
1364
|
+
"<doc><item>plain text</item></doc>"), 1);
|
|
1365
|
+
/* negative: c is not in the model */
|
|
1366
|
+
EXPECT_EQ(validates(
|
|
1367
|
+
"<!ELEMENT doc (item)*>\n"
|
|
1368
|
+
"<!ENTITY % mix \"(#PCDATA|b)*\">\n"
|
|
1369
|
+
"<!ELEMENT item %mix;>\n",
|
|
1370
|
+
"<doc><item>x<c/></item></doc>"), 0);
|
|
1371
|
+
/* the inline spelling must keep working (control) */
|
|
1372
|
+
EXPECT_EQ(validates(
|
|
1373
|
+
"<!ELEMENT doc (item)*>\n"
|
|
1374
|
+
"<!ELEMENT item (#PCDATA|b)*>\n",
|
|
1375
|
+
"<doc><item>x<b/>y</item></doc>"), 1);
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
TEST(DtdPhase8, NestedChoiceWithSequenceParsesAndBacktracks) {
|
|
1379
|
+
/* (a|b,c) inside a repetition: b,c runs must parse and match
|
|
1380
|
+
* through the backtracking path. */
|
|
1381
|
+
EXPECT_EQ(validates(
|
|
1382
|
+
"<!ELEMENT doc ((a|b,c))+>\n"
|
|
1383
|
+
"<!ELEMENT a EMPTY><!ELEMENT b EMPTY><!ELEMENT c EMPTY>\n",
|
|
1384
|
+
"<doc><b/><c/><b/><c/></doc>"), 1);
|
|
1385
|
+
EXPECT_EQ(validates(
|
|
1386
|
+
"<!ELEMENT doc ((a|b,c))+>\n"
|
|
1387
|
+
"<!ELEMENT a EMPTY><!ELEMENT b EMPTY><!ELEMENT c EMPTY>\n",
|
|
1388
|
+
"<doc><a/><b/><c/></doc>"), 1);
|
|
1389
|
+
/* negative: a lone b (the c is required by the b branch) */
|
|
1390
|
+
EXPECT_EQ(validates(
|
|
1391
|
+
"<!ELEMENT doc ((a|b,c))+>\n"
|
|
1392
|
+
"<!ELEMENT a EMPTY><!ELEMENT b EMPTY><!ELEMENT c EMPTY>\n",
|
|
1393
|
+
"<doc><b/></doc>"), 0);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1320
1396
|
TEST(DtdParse, MalformedDeclarationYieldsNull) {
|
|
1321
1397
|
const char* broken = "<!ELEMENT broken (>";
|
|
1322
1398
|
EXPECT_EQ(leptris_dtd_parse(broken, std::strlen(broken)),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="">
|
|
3
|
+
<start><element name="date"><ref name="bDateAttributes"/></element></start>
|
|
4
|
+
<define name="BibliographicDateType">
|
|
5
|
+
<choice>
|
|
6
|
+
<value>published</value>
|
|
7
|
+
<value>accessed</value>
|
|
8
|
+
</choice>
|
|
9
|
+
</define>
|
|
10
|
+
<define name="bDateAttributes">
|
|
11
|
+
<attribute name="type">
|
|
12
|
+
<choice>
|
|
13
|
+
<ref name="BibliographicDateType"/>
|
|
14
|
+
<text/>
|
|
15
|
+
</choice>
|
|
16
|
+
</attribute>
|
|
17
|
+
</define>
|
|
18
|
+
</grammar>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="">
|
|
3
|
+
<include href="dup-inc-shared.rng"/>
|
|
4
|
+
<define name="content" combine="interleave">
|
|
5
|
+
<zeroOrMore><element name="b"><empty/></element></zeroOrMore>
|
|
6
|
+
</define>
|
|
7
|
+
</grammar>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="">
|
|
3
|
+
<start><element name="root"><ref name="content"/></element></start>
|
|
4
|
+
<define name="content"><zeroOrMore><element name="a"><empty/></element></zeroOrMore></define>
|
|
5
|
+
</grammar>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="">
|
|
3
|
+
<include href="dup-inc-shared.rng"/>
|
|
4
|
+
<include href="dup-inc-mid.rng"/>
|
|
5
|
+
<start><element name="root"><ref name="content"/></element></start>
|
|
6
|
+
</grammar>
|
|
@@ -672,6 +672,44 @@ TEST(RngRegression, AttrValueConstraintBehindRefIsEnforcedAndEnumerated) {
|
|
|
672
672
|
leptris_rng_free(rng);
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
+
TEST(RngRegression, PositionErrorStillReportsAttributeErrors) {
|
|
676
|
+
/* leptris#1704 (Jing parity): an element that fails its
|
|
677
|
+
* position (p under sections) must STILL get its attributes
|
|
678
|
+
* validated — against its own definition — or schema-attribute
|
|
679
|
+
* constraints (align enums) go invisible exactly where
|
|
680
|
+
* documents are most broken. Jing reports both, position
|
|
681
|
+
* first. */
|
|
682
|
+
const char* sch = SCHEMA(
|
|
683
|
+
"<start><element name='r'>"
|
|
684
|
+
"<element name='clause'><text/></element>"
|
|
685
|
+
"</element></start>"
|
|
686
|
+
"<define name='p'>"
|
|
687
|
+
"<optional><attribute name='align'><ref name='vals'/></attribute>"
|
|
688
|
+
"</optional><text/></define>"
|
|
689
|
+
"<define name='vals'><choice>"
|
|
690
|
+
"<value>right</value><value>left</value>"
|
|
691
|
+
"<value>center</value><value>justified</value>"
|
|
692
|
+
"</choice></define>");
|
|
693
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
694
|
+
LeptrisRelaxNG rng = leptris_rng_parse(sch, strlen(sch), &st);
|
|
695
|
+
ASSERT_EQ(st, LEPTRIS_OK) << leptris_last_error();
|
|
696
|
+
ASSERT_NE(rng, nullptr);
|
|
697
|
+
const char doc[] = "<r><p align='mid-air'>t</p></r>";
|
|
698
|
+
LeptrisDocument d = leptris_parse_string(doc, strlen(doc), NULL);
|
|
699
|
+
ASSERT_NE(d, nullptr);
|
|
700
|
+
EXPECT_EQ(leptris_rng_validate(rng, d), 0);
|
|
701
|
+
const LeptrisRngErrorRecord* rep = NULL;
|
|
702
|
+
size_t n = leptris_rng_error_report(rng, &rep);
|
|
703
|
+
ASSERT_GE(n, 2u) << "expected position AND attribute errors";
|
|
704
|
+
EXPECT_NE(strstr(rep[0].message, "element \"p\" not allowed"),
|
|
705
|
+
nullptr) << rep[0].message;
|
|
706
|
+
EXPECT_NE(strstr(rep[1].message,
|
|
707
|
+
"value of attribute \"align\" is invalid"),
|
|
708
|
+
nullptr) << rep[1].message;
|
|
709
|
+
leptris_document_free(d);
|
|
710
|
+
leptris_rng_free(rng);
|
|
711
|
+
}
|
|
712
|
+
|
|
675
713
|
TEST(RngRegression, IncompleteNamesTheFirstRequiredElement) {
|
|
676
714
|
/* Jing matchEndTag: requiredElementNames() - the first
|
|
677
715
|
* non-nullable position's names (choice intersects, group
|
|
@@ -1142,6 +1180,42 @@ static int file_validates(const char* schema_name, const char* doc) {
|
|
|
1142
1180
|
return ok;
|
|
1143
1181
|
}
|
|
1144
1182
|
|
|
1183
|
+
TEST(RngInclude, BareRelativeSchemaFilenameResolvesSiblingIncludes) {
|
|
1184
|
+
/* A schema given as a BARE relative filename (no separator)
|
|
1185
|
+
* resolves its <include href="sibling.rng"> against the working
|
|
1186
|
+
* directory — not against the filename as a directory (#1709
|
|
1187
|
+
* follow-up: rng_dir_of left the filename in place). */
|
|
1188
|
+
const char* frag_path = "leptris_rng_bare_frag.rng";
|
|
1189
|
+
const char* main_path = "leptris_rng_bare_main.rng";
|
|
1190
|
+
const char frag_xml[] =
|
|
1191
|
+
"<grammar xmlns='http://relaxng.org/ns/structure/1.0'>"
|
|
1192
|
+
"<define name='shared'><element name='e'><empty/></element>"
|
|
1193
|
+
"</define></grammar>";
|
|
1194
|
+
const char main_xml[] =
|
|
1195
|
+
"<grammar xmlns='http://relaxng.org/ns/structure/1.0'>"
|
|
1196
|
+
"<include href='leptris_rng_bare_frag.rng'/>"
|
|
1197
|
+
"<start><ref name='shared'/></start></grammar>";
|
|
1198
|
+
FILE* f = fopen(frag_path, "wb");
|
|
1199
|
+
ASSERT_NE(f, nullptr);
|
|
1200
|
+
fwrite(frag_xml, 1, sizeof(frag_xml) - 1, f);
|
|
1201
|
+
fclose(f);
|
|
1202
|
+
f = fopen(main_path, "wb");
|
|
1203
|
+
ASSERT_NE(f, nullptr);
|
|
1204
|
+
fwrite(main_xml, 1, sizeof(main_xml) - 1, f);
|
|
1205
|
+
fclose(f);
|
|
1206
|
+
|
|
1207
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1208
|
+
LeptrisRelaxNG rng = leptris_rng_parse_file(main_path, &st);
|
|
1209
|
+
ASSERT_NE(rng, nullptr) << leptris_status_string(st);
|
|
1210
|
+
LeptrisDocument d = leptris_parse_string("<e/>", 4, &st);
|
|
1211
|
+
ASSERT_NE(d, nullptr);
|
|
1212
|
+
EXPECT_EQ(leptris_rng_validate(rng, d), 1);
|
|
1213
|
+
leptris_document_free(d);
|
|
1214
|
+
leptris_rng_free(rng);
|
|
1215
|
+
remove(frag_path);
|
|
1216
|
+
remove(main_path);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1145
1219
|
TEST(RngInclude, MergesDefinesFromIncludedGrammar) {
|
|
1146
1220
|
EXPECT_EQ(file_validates("main.rng", "<e/>"), 1);
|
|
1147
1221
|
EXPECT_EQ(file_validates("main.rng", "<x/>"), 0);
|
|
@@ -1411,3 +1485,30 @@ TEST(RngIncludeMultiHop, ChoiceUnionSurvivesIncludeHop) {
|
|
|
1411
1485
|
EXPECT_EQ(file_validates("comb3-choice-outer.rng", "<root><z/></root>"),
|
|
1412
1486
|
0);
|
|
1413
1487
|
}
|
|
1488
|
+
|
|
1489
|
+
/* ---- leptris#1709: multi-depth combines + duplicated includes ----- */
|
|
1490
|
+
|
|
1491
|
+
TEST(Rng1709Shapes, DuplicatedIncludeKeepsBothBranches) {
|
|
1492
|
+
/* shared included DIRECTLY and via mid: the direct include's
|
|
1493
|
+
* merge must not clobber mid's combined branch (the two paths
|
|
1494
|
+
* shared one body tree in the first cut). */
|
|
1495
|
+
EXPECT_EQ(file_validates("dup-inc-top.rng", "<root><a/><b/></root>"),
|
|
1496
|
+
1);
|
|
1497
|
+
EXPECT_EQ(file_validates("dup-inc-top.rng", "<root><a/></root>"), 1);
|
|
1498
|
+
EXPECT_EQ(file_validates("dup-inc-top.rng", "<root><b/></root>"), 1);
|
|
1499
|
+
EXPECT_EQ(file_validates("dup-inc-top.rng", "<root><z/></root>"), 0);
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
TEST(Rng1709Shapes, AttributeChoiceWithTextBranchAcceptsAny) {
|
|
1503
|
+
/* bDateAttributes shape: CHOICE[enum-ref, text] — the text
|
|
1504
|
+
* branch accepts values outside the enum. */
|
|
1505
|
+
EXPECT_EQ(file_validates("attr-text-choice.rng",
|
|
1506
|
+
"<date type='published'/>"),
|
|
1507
|
+
1);
|
|
1508
|
+
EXPECT_EQ(file_validates("attr-text-choice.rng",
|
|
1509
|
+
"<date type='effective'/>"),
|
|
1510
|
+
1);
|
|
1511
|
+
/* attribute absent: the attribute is required by its own
|
|
1512
|
+
* definition here, but the harness shape keeps it simple — the
|
|
1513
|
+
* enum hit and text hit are the contract under test. */
|
|
1514
|
+
}
|