Skip to content

Commit 920899a

Browse files
committed
Merge commit '4b3f860e5420ade19a825dc7f4d75789489535ba'
2 parents 52bf25a + 4b3f860 commit 920899a

24 files changed

+537
-120
lines changed

HTMLparser.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6185,6 +6185,12 @@ htmlCtxtReset(htmlParserCtxtPtr ctxt)
61856185
ctxt->extSubURI = NULL;
61866186
DICT_FREE(ctxt->extSubSystem);
61876187
ctxt->extSubSystem = NULL;
6188+
6189+
if (ctxt->directory != NULL) {
6190+
xmlFree(ctxt->directory);
6191+
ctxt->directory = NULL;
6192+
}
6193+
61886194
if (ctxt->myDoc != NULL)
61896195
xmlFreeDoc(ctxt->myDoc);
61906196
ctxt->myDoc = NULL;

HTMLtree.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -385,22 +385,17 @@ htmlFindOutputEncoder(const char *encoding) {
385385
xmlCharEncodingHandler *handler = NULL;
386386

387387
if (encoding != NULL) {
388-
xmlCharEncoding enc;
388+
int res;
389389

390-
enc = xmlParseCharEncoding(encoding);
391-
if (enc != XML_CHAR_ENCODING_UTF8) {
392-
xmlOpenCharEncodingHandler(encoding, /* output */ 1, &handler);
393-
if (handler == NULL)
394-
htmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding);
395-
}
390+
res = xmlOpenCharEncodingHandler(encoding, /* output */ 1,
391+
&handler);
392+
if (res != XML_ERR_OK)
393+
htmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding);
396394
} else {
397395
/*
398-
* Fallback to HTML or ASCII when the encoding is unspecified
396+
* Fallback to HTML when the encoding is unspecified
399397
*/
400-
if (handler == NULL)
401-
xmlOpenCharEncodingHandler("HTML", /* output */ 1, &handler);
402-
if (handler == NULL)
403-
xmlOpenCharEncodingHandler("ascii", /* output */ 1, &handler);
398+
xmlOpenCharEncodingHandler("HTML", /* output */ 1, &handler);
404399
}
405400

406401
return(handler);

NEWS

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
NEWS file for libxml2
22

3+
v2.13.2: Jul 4 2024
4+
5+
### Regressions
6+
7+
- tree: Fix handling of empty strings in xmlNodeParseContent
8+
- valid: Restore ID lookup
9+
- parser: Reenable ctxt->directory
10+
- uri: Handle filesystem paths in xmlBuildRelativeURISafe
11+
- encoding: Make xmlFindCharEncodingHandler return UTF-8 handler
12+
- encoding: Fix encoding lookup with xmlOpenCharEncodingHandler
13+
- include: Define ATTRIBUTE_UNUSED for clang
14+
- uri: Fix xmlBuildURI with NULL base
15+
16+
### Improvements
17+
18+
- uri: Enable Windows paths on Cygwin
19+
- tests: Clarify licence of test/intsubset2.xml
20+
21+
322
v2.13.1: Jun 19 2024
423

524
### Regressions
@@ -57,8 +76,12 @@ to be enabled by passing --with-zlib, --with-lzma or --with-http to
5776
configure. In legacy mode (--with-legacy) these options are enabled
5877
by default as before.
5978

60-
Support for FTP and xpointer() XPath extensions will be removed in
61-
the next release.
79+
Support for FTP will be removed in the next release.
80+
81+
Support for the range and point extensions of the xpointer() scheme
82+
will be removed in the next release. The rest of the XPointer
83+
implementation won't be affected. The xpointer() scheme will behave
84+
like the xpath1() scheme.
6285

6386
Several more legacy symbols were deprecated. Users of the old "SAX1"
6487
API functions are encouraged to upgrade to the new "SAX2" API,

SAX2.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,13 @@ xmlSAX2ResolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId
412412
if (ctxt->input != NULL)
413413
base = BAD_CAST ctxt->input->filename;
414414

415+
/*
416+
* We don't really need the 'directory' struct member, but some
417+
* users set it manually to a base URI for memory streams.
418+
*/
419+
if (base == NULL)
420+
base = BAD_CAST ctxt->directory;
421+
415422
if ((xmlStrlen(systemId) > XML_MAX_URI_LENGTH) ||
416423
(xmlStrlen(base) > XML_MAX_URI_LENGTH)) {
417424
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
@@ -574,6 +581,13 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type,
574581
}
575582
}
576583

584+
/*
585+
* We don't really need the 'directory' struct member, but some
586+
* users set it manually to a base URI for memory streams.
587+
*/
588+
if (base == NULL)
589+
base = ctxt->directory;
590+
577591
res = xmlBuildURISafe(systemId, (const xmlChar *) base, &URI);
578592

579593
if (URI == NULL) {
@@ -1255,6 +1269,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
12551269
} else
12561270
#endif /* LIBXML_VALID_ENABLED */
12571271
if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
1272+
(ctxt->input->entity == NULL) &&
12581273
/* Don't create IDs containing entity references */
12591274
(ret->children != NULL) &&
12601275
(ret->children->type == XML_TEXT_NODE) &&
@@ -1987,6 +2002,7 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
19872002
} else
19882003
#endif /* LIBXML_VALID_ENABLED */
19892004
if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
2005+
(ctxt->input->entity == NULL) &&
19902006
/* Don't create IDs containing entity references */
19912007
(ret->children != NULL) &&
19922008
(ret->children->type == XML_TEXT_NODE) &&

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], 13)
6-
m4_define([MICRO_VERSION], 1)
6+
m4_define([MICRO_VERSION], 2)
77

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

encoding.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,9 +1279,8 @@ DECLARE_ISO_FUNCS(16)
12791279
{ (char *) name, in, out EMPTY_ICONV EMPTY_UCONV }
12801280

12811281
static const xmlCharEncodingHandler defaultHandlers[] = {
1282-
MAKE_HANDLER("UTF-8", UTF8ToUTF8, UTF8ToUTF8)
12831282
#ifdef LIBXML_OUTPUT_ENABLED
1284-
,MAKE_HANDLER("UTF-16LE", UTF16LEToUTF8, UTF8ToUTF16LE)
1283+
MAKE_HANDLER("UTF-16LE", UTF16LEToUTF8, UTF8ToUTF16LE)
12851284
,MAKE_HANDLER("UTF-16BE", UTF16BEToUTF8, UTF8ToUTF16BE)
12861285
,MAKE_HANDLER("UTF-16", UTF16LEToUTF8, UTF8ToUTF16)
12871286
,MAKE_HANDLER("ISO-8859-1", isolat1ToUTF8, UTF8Toisolat1)
@@ -1291,7 +1290,7 @@ static const xmlCharEncodingHandler defaultHandlers[] = {
12911290
,MAKE_HANDLER("HTML", NULL, UTF8ToHtml)
12921291
#endif
12931292
#else
1294-
,MAKE_HANDLER("UTF-16LE", UTF16LEToUTF8, NULL)
1293+
MAKE_HANDLER("UTF-16LE", UTF16LEToUTF8, NULL)
12951294
,MAKE_HANDLER("UTF-16BE", UTF16BEToUTF8, NULL)
12961295
,MAKE_HANDLER("UTF-16", UTF16LEToUTF8, NULL)
12971296
,MAKE_HANDLER("ISO-8859-1", isolat1ToUTF8, NULL)
@@ -1321,10 +1320,13 @@ static const xmlCharEncodingHandler defaultHandlers[] = {
13211320
#define NUM_DEFAULT_HANDLERS \
13221321
(sizeof(defaultHandlers) / sizeof(defaultHandlers[0]))
13231322

1324-
static const xmlCharEncodingHandler *xmlUTF16LEHandler = &defaultHandlers[1];
1325-
static const xmlCharEncodingHandler *xmlUTF16BEHandler = &defaultHandlers[2];
1326-
static const xmlCharEncodingHandler *xmlLatin1Handler = &defaultHandlers[4];
1327-
static const xmlCharEncodingHandler *xmlAsciiHandler = &defaultHandlers[5];
1323+
static const xmlCharEncodingHandler xmlUTF8Handler =
1324+
MAKE_HANDLER("UTF-8", UTF8ToUTF8, UTF8ToUTF8);
1325+
1326+
static const xmlCharEncodingHandler *xmlUTF16LEHandler = &defaultHandlers[0];
1327+
static const xmlCharEncodingHandler *xmlUTF16BEHandler = &defaultHandlers[1];
1328+
static const xmlCharEncodingHandler *xmlLatin1Handler = &defaultHandlers[3];
1329+
static const xmlCharEncodingHandler *xmlAsciiHandler = &defaultHandlers[4];
13281330

13291331
/* the size should be growable, but it's not a big deal ... */
13301332
#define MAX_ENCODING_HANDLERS 50
@@ -1922,6 +1924,9 @@ xmlGetCharEncodingHandler(xmlCharEncoding enc) {
19221924
*
19231925
* The handler must be closed with xmlCharEncCloseFunc.
19241926
*
1927+
* If the encoding is UTF-8, a NULL handler and no error code will
1928+
* be returned.
1929+
*
19251930
* Available since 2.13.0.
19261931
*
19271932
* Returns an xmlParserErrors error code.
@@ -1941,6 +1946,10 @@ xmlOpenCharEncodingHandler(const char *name, int output,
19411946
if (name == NULL)
19421947
return(XML_ERR_ARGUMENT);
19431948

1949+
if ((xmlStrcasecmp(BAD_CAST name, BAD_CAST "UTF-8") == 0) ||
1950+
(xmlStrcasecmp(BAD_CAST name, BAD_CAST "UTF8") == 0))
1951+
return(XML_ERR_OK);
1952+
19441953
/*
19451954
* Do the alias resolution
19461955
*/
@@ -1957,6 +1966,9 @@ xmlOpenCharEncodingHandler(const char *name, int output,
19571966

19581967
/*
19591968
* Fallback using the canonical names
1969+
*
1970+
* TODO: We should make sure that the name of the returned
1971+
* handler equals norig.
19601972
*/
19611973
enc = xmlParseCharEncoding(norig);
19621974
return(xmlLookupCharEncodingHandler(enc, out));
@@ -1976,6 +1988,14 @@ xmlCharEncodingHandlerPtr
19761988
xmlFindCharEncodingHandler(const char *name) {
19771989
xmlCharEncodingHandler *ret;
19781990

1991+
/*
1992+
* This handler shouldn't be used, but we must return a non-NULL
1993+
* handler.
1994+
*/
1995+
if ((xmlStrcasecmp(BAD_CAST name, BAD_CAST "UTF-8") == 0) ||
1996+
(xmlStrcasecmp(BAD_CAST name, BAD_CAST "UTF8") == 0))
1997+
return((xmlCharEncodingHandlerPtr) &xmlUTF8Handler);
1998+
19791999
xmlOpenCharEncodingHandler(name, 0, &ret);
19802000
return(ret);
19812001
}

include/libxml/xmlexports.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*/
4343

4444
#ifndef ATTRIBUTE_UNUSED
45-
#if __GNUC__ * 100 + __GNUC_MINOR__ >= 207
45+
#if __GNUC__ * 100 + __GNUC_MINOR__ >= 207 || defined(__clang__)
4646
#define ATTRIBUTE_UNUSED __attribute__((unused))
4747
#else
4848
#define ATTRIBUTE_UNUSED

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(
22
'libxml2',
33
'c',
4-
version: '2.13.0',
4+
version: '2.13.2',
55
license: 'MIT',
66
default_options: ['buildtype=debug', 'warning_level=3'],
77
meson_version: '>= 0.61',

parser.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,8 +1940,11 @@ xmlCtxtGrowAttrs(xmlParserCtxtPtr ctxt, int nr) {
19401940
int
19411941
inputPush(xmlParserCtxtPtr ctxt, xmlParserInputPtr value)
19421942
{
1943+
char *directory = NULL;
1944+
19431945
if ((ctxt == NULL) || (value == NULL))
19441946
return(-1);
1947+
19451948
if (ctxt->inputNr >= ctxt->inputMax) {
19461949
size_t newSize = ctxt->inputMax * 2;
19471950
xmlParserInputPtr *tmp;
@@ -1955,9 +1958,24 @@ inputPush(xmlParserCtxtPtr ctxt, xmlParserInputPtr value)
19551958
ctxt->inputTab = tmp;
19561959
ctxt->inputMax = newSize;
19571960
}
1961+
1962+
if ((ctxt->inputNr == 0) && (value->filename != NULL)) {
1963+
directory = xmlParserGetDirectory(value->filename);
1964+
if (directory == NULL) {
1965+
xmlErrMemory(ctxt);
1966+
return(-1);
1967+
}
1968+
}
1969+
19581970
ctxt->inputTab[ctxt->inputNr] = value;
19591971
ctxt->input = value;
1960-
return (ctxt->inputNr++);
1972+
1973+
if (ctxt->inputNr == 0) {
1974+
xmlFree(ctxt->directory);
1975+
ctxt->directory = directory;
1976+
}
1977+
1978+
return(ctxt->inputNr++);
19611979
}
19621980
/**
19631981
* inputPop:
@@ -13269,6 +13287,12 @@ xmlCtxtReset(xmlParserCtxtPtr ctxt)
1326913287
ctxt->extSubURI = NULL;
1327013288
DICT_FREE(ctxt->extSubSystem);
1327113289
ctxt->extSubSystem = NULL;
13290+
13291+
if (ctxt->directory != NULL) {
13292+
xmlFree(ctxt->directory);
13293+
ctxt->directory = NULL;
13294+
}
13295+
1327213296
if (ctxt->myDoc != NULL)
1327313297
xmlFreeDoc(ctxt->myDoc);
1327413298
ctxt->myDoc = NULL;

parserInternals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,7 @@ xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
24692469
if (ctxt->sax != NULL)
24702470
#endif /* LIBXML_SAX1_ENABLED */
24712471
xmlFree(ctxt->sax);
2472+
if (ctxt->directory != NULL) xmlFree(ctxt->directory);
24722473
if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
24732474
if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
24742475
if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);

0 commit comments

Comments
 (0)