1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2026-01-26 21:41:34 +03:00

xmllint: Add --strict-namespace option

Use xmlCtxtGetStatus() after parsing. If status indicates a namespace error while the --strict-namespace option is enabled, xmllint will exit with XMLLINT_ERR_RDFILE error

Fixes #698
This commit is contained in:
Michael Mann
2025-06-18 13:55:37 -04:00
committed by Nick Wellnhofer
parent bf26cf9d08
commit dd2b4091fb
2 changed files with 26 additions and 4 deletions

View File

@@ -93,6 +93,7 @@
<arg choice="plain"><option>--output <replaceable class="option">FILE</replaceable></option></arg>
<arg choice="plain"><option>--repeat</option></arg>
<arg choice="plain"><option>--insert</option></arg>
<arg choice="plain"><option>--strict-namespace</option></arg>
<arg choice="plain"><option>--compress</option></arg>
<arg choice="plain"><option>--html</option></arg>
<arg choice="plain"><option>--xmlout</option></arg>
@@ -223,6 +224,16 @@
</listitem>
</varlistentry>
<varlistentry>
<term><option>--strict-namespace</option></term>
<listitem>
<para>
Determine if the document is a well-formed, but has namespace
errors. This enforces namespace-well-formedness.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@@ -161,7 +161,9 @@ typedef enum {
/** Deactivate all catalogs */
XML_LINT_USE_NO_CATALOGS = (1 << 22),
/** Print trace of all external entities loaded */
XML_LINT_USE_LOAD_TRACE = (1 << 23)
XML_LINT_USE_LOAD_TRACE = (1 << 23),
/** Return application failure if document has any namespace errors */
XML_LINT_STRICT_NAMESPACE = (1 << 24)
} xmllintAppOptions;
@@ -1768,10 +1770,15 @@ parseFile(xmllintState *lint, const char *filename) {
else
lint->progresult = XMLLINT_ERR_RDFILE;
} else {
#ifdef LIBXML_VALID_ENABLED
if ((lint->parseOptions & XML_PARSE_DTDVALID) && (lint->ctxt->valid == 0))
xmlParserStatus status = xmlCtxtGetStatus(lint->ctxt);
if ((lint->parseOptions & XML_PARSE_DTDVALID) &&
(status & XML_STATUS_DTD_VALIDATION_FAILED))
lint->progresult = XMLLINT_ERR_VALID;
#endif /* LIBXML_VALID_ENABLED */
if ((lint->appOptions & XML_LINT_STRICT_NAMESPACE) &&
(status & XML_STATUS_NOT_NS_WELL_FORMED)) {
lint->progresult = XMLLINT_ERR_RDFILE;
}
}
return(doc);
@@ -2321,6 +2328,7 @@ static void usage(FILE *f, const char *name) {
fprintf(f, "\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
fprintf(f, "\t--insert : ad-hoc test for valid insertions\n");
#endif /* LIBXML_VALID_ENABLED */
fprintf(f, "\t--strict-namespace : Return application failure if document has any namespace errors\n");
fprintf(f, "\t--quiet : be quiet when succeeded\n");
fprintf(f, "\t--timing : print some timings\n");
fprintf(f, "\t--repeat : repeat 100 times, for timing or profiling\n");
@@ -2606,6 +2614,9 @@ xmllintParseOptions(xmllintState *lint, int argc, const char **argv) {
(!strcmp(argv[i], "--insert"))) {
lint->appOptions |= XML_LINT_VALID_INSERTIONS;
#endif /* LIBXML_VALID_ENABLED */
} else if ((!strcmp(argv[i], "-strict-namespace")) ||
(!strcmp(argv[i], "--strict-namespace"))) {
lint->appOptions |= XML_LINT_STRICT_NAMESPACE;
} else if ((!strcmp(argv[i], "-dropdtd")) ||
(!strcmp(argv[i], "--dropdtd"))) {
lint->appOptions |= XML_LINT_DROP_DTD;