1From b1b654171e44dba90bbc6836ca05dd4e1161b4b0 Mon Sep 17 00:00:00 2001 2From: Nick Wellnhofer <wellnhofer@aevum.de> 3Date: Sat, 20 Aug 2022 15:15:04 +0200 4Subject: [PATCH] Create stream with buffer in xmlNewStringInputStream 5 6Create an input stream with a buffer in xmlNewStringInputStream. 7Otherwise, switching encodings won't work. 8 9See #34. 10Reference:https://github.com/GNOME/libxml2/commit/b1b654171e44dba90bbc6836ca05dd4e1161b4b0 11Conflict:NA 12--- 13 parserInternals.c | 15 +++++++++++---- 14 1 file changed, 11 insertions(+), 4 deletions(-) 15 16diff --git a/parserInternals.c b/parserInternals.c 17index d68592f..6ef7671 100644 18--- a/parserInternals.c 19+++ b/parserInternals.c 20@@ -1465,6 +1465,7 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { 21 xmlParserInputPtr 22 xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) { 23 xmlParserInputPtr input; 24+ xmlParserInputBufferPtr buf; 25 26 if (buffer == NULL) { 27 xmlErrInternal(ctxt, "xmlNewStringInputStream string = NULL\n", 28@@ -1474,15 +1475,21 @@ xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) { 29 if (xmlParserDebugEntities) 30 xmlGenericError(xmlGenericErrorContext, 31 "new fixed input: %.30s\n", buffer); 32+ buf = xmlParserInputBufferCreateMem((const char *) buffer, 33+ strlen((const char *) buffer), 34+ XML_CHAR_ENCODING_NONE); 35+ if (buf == NULL) { 36+ xmlErrMemory(ctxt, NULL); 37+ return(NULL); 38+ } 39 input = xmlNewInputStream(ctxt); 40 if (input == NULL) { 41 xmlErrMemory(ctxt, "couldn't allocate a new input stream\n"); 42+ xmlFreeParserInputBuffer(buf); 43 return(NULL); 44 } 45- input->base = buffer; 46- input->cur = buffer; 47- input->length = xmlStrlen(buffer); 48- input->end = &buffer[input->length]; 49+ input->buf = buf; 50+ xmlBufResetInput(input->buf->buffer, input); 51 return(input); 52 } 53 54-- 552.27.0 56 57