Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit 11cf2a3

Browse files
committed
Merge commit '505e2e872e767405be565aa9d47ae9d6d5677f79'
2 parents caf7e6f + 505e2e8 commit 11cf2a3

13 files changed

Lines changed: 122 additions & 43 deletions

File tree

HTMLparser.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5987,7 +5987,7 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
59875987

59885988
xmlInitParser();
59895989

5990-
buf = xmlAllocParserInputBuffer(enc);
5990+
buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE);
59915991
if (buf == NULL) return(NULL);
59925992

59935993
ctxt = htmlNewSAXParserCtxt(sax, user_data);
@@ -6018,6 +6018,9 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
60186018

60196019
inputPush(ctxt, inputStream);
60206020

6021+
if (enc != XML_CHAR_ENCODING_NONE)
6022+
xmlSwitchEncoding(ctxt, enc);
6023+
60216024
if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
60226025
(ctxt->input->buf != NULL)) {
60236026
size_t pos = ctxt->input->cur - ctxt->input->base;

NEWS

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
NEWS file for libxml2
22

3+
v2.12.6: Mar 15 2024
4+
5+
### Regressions
6+
7+
- parser: Fix detection of duplicate attributes in XML namespace
8+
- xmlreader: Fix xmlTextReaderConstEncoding
9+
- html: Fix htmlCreatePushParserCtxt with encoding
10+
- xmllint: Return error code if XPath returns empty nodeset
11+
12+
313
v2.12.5: Feb 4 2024
414

515
### Security

SAX2.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -955,17 +955,7 @@ xmlSAX2EndDocument(void *ctx)
955955

956956
doc = ctxt->myDoc;
957957
if ((doc != NULL) && (doc->encoding == NULL)) {
958-
const xmlChar *encoding = NULL;
959-
960-
if ((ctxt->input->flags & XML_INPUT_USES_ENC_DECL) ||
961-
(ctxt->input->flags & XML_INPUT_AUTO_ENCODING)) {
962-
/* Preserve encoding exactly */
963-
encoding = ctxt->encoding;
964-
} else if ((ctxt->input->buf) && (ctxt->input->buf->encoder)) {
965-
encoding = BAD_CAST ctxt->input->buf->encoder->name;
966-
} else if (ctxt->input->flags & XML_INPUT_HAS_ENCODING) {
967-
encoding = BAD_CAST "UTF-8";
968-
}
958+
const xmlChar *encoding = xmlGetActualEncoding(ctxt);
969959

970960
if (encoding != NULL) {
971961
doc->encoding = xmlStrdup(encoding);

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ AC_PREREQ([2.63])
33

44
m4_define([MAJOR_VERSION], 2)
55
m4_define([MINOR_VERSION], 12)
6-
m4_define([MICRO_VERSION], 5)
6+
m4_define([MICRO_VERSION], 6)
77

88
AC_INIT([libxml2],[MAJOR_VERSION.MINOR_VERSION.MICRO_VERSION])
99
AC_CONFIG_SRCDIR([entities.c])

doc/xmllint.1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.\" Title: xmllint
33
.\" Author: John Fleck <jfleck@inkstain.net>
44
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5-
.\" Date: 11/04/2023
5+
.\" Date: 03/15/2024
66
.\" Manual: xmllint Manual
77
.\" Source: libxml2
88
.\" Language: English
99
.\"
10-
.TH "XMLLINT" "1" "11/04/2023" "libxml2" "xmllint Manual"
10+
.TH "XMLLINT" "1" "03/15/2024" "libxml2" "xmllint Manual"
1111
.\" -----------------------------------------------------------------
1212
.\" * Define some portability stuff
1313
.\" -----------------------------------------------------------------
@@ -357,7 +357,7 @@ the section called \(lqSHELL COMMANDS\(rq)\&.
357357
.PP
358358
\fB\-\-xpath "\fR\fB\fIXPath_expression\fR\fR\fB"\fR
359359
.RS 4
360-
Run an XPath expression given as argument and print the result\&. In case of a nodeset result, each node in the node set is serialized in full in the output\&. In case of an empty node set the "XPath set is empty" result will be shown and an error exit code will be returned\&.
360+
Run an XPath expression given as argument and print the result\&. In case of a nodeset result, each node in the node set is serialized in full in the output\&. In case of an empty node set the "XPath set is empty" result will be shown and exit code 11 will be returned\&.\&. This feature is EXPERIMENTAL\&. Implementation details can change without futher notice\&.
361361
.RE
362362
.PP
363363
\fB\-\-stream\fR
@@ -615,6 +615,11 @@ Out of memory error
615615
.RS 4
616616
XPath evaluation error
617617
.RE
618+
.PP
619+
\fB11\fR
620+
.RS 4
621+
XPath result is empty
622+
.RE
618623
.SH "SEE ALSO"
619624
.PP
620625
\fBlibxml\fR(3)

doc/xmllint.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@
9797
result. In case of a nodeset result, each node in the
9898
node set is serialized in full in the output. In case
9999
of an empty node set the "XPath set is empty" result
100-
will be shown and an error exit code will be returned.
100+
will be shown and exit code 11 will be returned..
101+
This feature is EXPERIMENTAL. Implementation details can
102+
change without futher notice.
101103
</p></dd><dt><span class="term"><code class="option">--stream</code></span></dt><dd><p>
102104
Use streaming <acronym class="acronym">API</acronym> - useful when used in combination
103105
with <code class="option">--relaxng</code> or <code class="option">--valid</code> options
@@ -162,7 +164,7 @@
162164
</p></dd><dt><span class="term"><span class="errorcode">8</span></span></dt><dd><p>
163165
Error in Reader registration (generated
164166
when <code class="option">--chkregister</code> option is used)
165-
</p></dd><dt><span class="term"><span class="errorcode">9</span></span></dt><dd><p>Out of memory error</p></dd><dt><span class="term"><span class="errorcode">10</span></span></dt><dd><p>XPath evaluation error</p></dd></dl></div></div><div class="refsect1"><a name="seealso"></a><h2>SEE ALSO</h2><p><span class="citerefentry"><span class="refentrytitle">libxml</span>(3)</span>
167+
</p></dd><dt><span class="term"><span class="errorcode">9</span></span></dt><dd><p>Out of memory error</p></dd><dt><span class="term"><span class="errorcode">10</span></span></dt><dd><p>XPath evaluation error</p></dd><dt><span class="term"><span class="errorcode">11</span></span></dt><dd><p>XPath result is empty</p></dd></dl></div></div><div class="refsect1"><a name="seealso"></a><h2>SEE ALSO</h2><p><span class="citerefentry"><span class="refentrytitle">libxml</span>(3)</span>
166168
</p><p>
167169
More information can be found at
168170
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><span class="citerefentry"><span class="refentrytitle">libxml</span>(3)</span> web page <a class="ulink" href="https://gitlab.gnome.org/GNOME/libxml2" target="_top">https://gitlab.gnome.org/GNOME/libxml2</a>

doc/xmllint.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,9 @@
575575
result. In case of a nodeset result, each node in the
576576
node set is serialized in full in the output. In case
577577
of an empty node set the "XPath set is empty" result
578-
will be shown and an error exit code will be returned.
578+
will be shown and exit code 11 will be returned..
579+
This feature is EXPERIMENTAL. Implementation details can
580+
change without futher notice.
579581
</para>
580582
</listitem>
581583
</varlistentry>
@@ -945,6 +947,13 @@
945947
</listitem>
946948
</varlistentry>
947949

950+
<varlistentry>
951+
<term><errorcode>11</errorcode></term>
952+
<listitem>
953+
<para>XPath result is empty</para>
954+
</listitem>
955+
</varlistentry>
956+
948957
</variablelist>
949958
</refsect1>
950959

include/private/parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ XML_HIDDEN void
4848
xmlDetectEncoding(xmlParserCtxtPtr ctxt);
4949
XML_HIDDEN void
5050
xmlSetDeclaredEncoding(xmlParserCtxtPtr ctxt, xmlChar *encoding);
51+
XML_HIDDEN const xmlChar *
52+
xmlGetActualEncoding(xmlParserCtxtPtr ctxt);
5153

5254
XML_HIDDEN xmlParserNsData *
5355
xmlParserNsCreate(void);

parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9424,7 +9424,7 @@ xmlAttrHashInsert(xmlParserCtxtPtr ctxt, unsigned size, const xmlChar *name,
94249424
int nsIndex = (int) (ptrdiff_t) atts[2];
94259425

94269426
if ((nsIndex == NS_INDEX_EMPTY) ? (uri == NULL) :
9427-
(nsIndex == NS_INDEX_XML) ? (uri == ctxt->str_xml) :
9427+
(nsIndex == NS_INDEX_XML) ? (uri == ctxt->str_xml_ns) :
94289428
(uri == ctxt->nsTab[nsIndex * 2 + 1]))
94299429
return(bucket->index);
94309430
}

parserInternals.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,30 @@ xmlSetDeclaredEncoding(xmlParserCtxtPtr ctxt, xmlChar *encoding) {
14791479
}
14801480
}
14811481

1482+
/**
1483+
* xmlGetActualEncoding:
1484+
* @ctxt: the parser context
1485+
*
1486+
* Returns the actual used to parse the document. This can differ from
1487+
* the declared encoding.
1488+
*/
1489+
const xmlChar *
1490+
xmlGetActualEncoding(xmlParserCtxtPtr ctxt) {
1491+
const xmlChar *encoding = NULL;
1492+
1493+
if ((ctxt->input->flags & XML_INPUT_USES_ENC_DECL) ||
1494+
(ctxt->input->flags & XML_INPUT_AUTO_ENCODING)) {
1495+
/* Preserve encoding exactly */
1496+
encoding = ctxt->encoding;
1497+
} else if ((ctxt->input->buf) && (ctxt->input->buf->encoder)) {
1498+
encoding = BAD_CAST ctxt->input->buf->encoder->name;
1499+
} else if (ctxt->input->flags & XML_INPUT_HAS_ENCODING) {
1500+
encoding = BAD_CAST "UTF-8";
1501+
}
1502+
1503+
return(encoding);
1504+
}
1505+
14821506
/************************************************************************
14831507
* *
14841508
* Commodity functions to handle entities processing *

0 commit comments

Comments
 (0)