153aa9179Sopenharmony_ciFrom b1b654171e44dba90bbc6836ca05dd4e1161b4b0 Mon Sep 17 00:00:00 2001 253aa9179Sopenharmony_ciFrom: Nick Wellnhofer <wellnhofer@aevum.de> 353aa9179Sopenharmony_ciDate: Sat, 20 Aug 2022 15:15:04 +0200 453aa9179Sopenharmony_ciSubject: [PATCH] Create stream with buffer in xmlNewStringInputStream 553aa9179Sopenharmony_ci 653aa9179Sopenharmony_ciCreate an input stream with a buffer in xmlNewStringInputStream. 753aa9179Sopenharmony_ciOtherwise, switching encodings won't work. 853aa9179Sopenharmony_ci 953aa9179Sopenharmony_ciSee #34. 1053aa9179Sopenharmony_ciReference:https://github.com/GNOME/libxml2/commit/b1b654171e44dba90bbc6836ca05dd4e1161b4b0 1153aa9179Sopenharmony_ciConflict:NA 1253aa9179Sopenharmony_ci--- 1353aa9179Sopenharmony_ci parserInternals.c | 15 +++++++++++---- 1453aa9179Sopenharmony_ci 1 file changed, 11 insertions(+), 4 deletions(-) 1553aa9179Sopenharmony_ci 1653aa9179Sopenharmony_cidiff --git a/parserInternals.c b/parserInternals.c 1753aa9179Sopenharmony_ciindex d68592f..6ef7671 100644 1853aa9179Sopenharmony_ci--- a/parserInternals.c 1953aa9179Sopenharmony_ci+++ b/parserInternals.c 2053aa9179Sopenharmony_ci@@ -1465,6 +1465,7 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { 2153aa9179Sopenharmony_ci xmlParserInputPtr 2253aa9179Sopenharmony_ci xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) { 2353aa9179Sopenharmony_ci xmlParserInputPtr input; 2453aa9179Sopenharmony_ci+ xmlParserInputBufferPtr buf; 2553aa9179Sopenharmony_ci 2653aa9179Sopenharmony_ci if (buffer == NULL) { 2753aa9179Sopenharmony_ci xmlErrInternal(ctxt, "xmlNewStringInputStream string = NULL\n", 2853aa9179Sopenharmony_ci@@ -1474,15 +1475,21 @@ xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) { 2953aa9179Sopenharmony_ci if (xmlParserDebugEntities) 3053aa9179Sopenharmony_ci xmlGenericError(xmlGenericErrorContext, 3153aa9179Sopenharmony_ci "new fixed input: %.30s\n", buffer); 3253aa9179Sopenharmony_ci+ buf = xmlParserInputBufferCreateMem((const char *) buffer, 3353aa9179Sopenharmony_ci+ strlen((const char *) buffer), 3453aa9179Sopenharmony_ci+ XML_CHAR_ENCODING_NONE); 3553aa9179Sopenharmony_ci+ if (buf == NULL) { 3653aa9179Sopenharmony_ci+ xmlErrMemory(ctxt, NULL); 3753aa9179Sopenharmony_ci+ return(NULL); 3853aa9179Sopenharmony_ci+ } 3953aa9179Sopenharmony_ci input = xmlNewInputStream(ctxt); 4053aa9179Sopenharmony_ci if (input == NULL) { 4153aa9179Sopenharmony_ci xmlErrMemory(ctxt, "couldn't allocate a new input stream\n"); 4253aa9179Sopenharmony_ci+ xmlFreeParserInputBuffer(buf); 4353aa9179Sopenharmony_ci return(NULL); 4453aa9179Sopenharmony_ci } 4553aa9179Sopenharmony_ci- input->base = buffer; 4653aa9179Sopenharmony_ci- input->cur = buffer; 4753aa9179Sopenharmony_ci- input->length = xmlStrlen(buffer); 4853aa9179Sopenharmony_ci- input->end = &buffer[input->length]; 4953aa9179Sopenharmony_ci+ input->buf = buf; 5053aa9179Sopenharmony_ci+ xmlBufResetInput(input->buf->buffer, input); 5153aa9179Sopenharmony_ci return(input); 5253aa9179Sopenharmony_ci } 5353aa9179Sopenharmony_ci 5453aa9179Sopenharmony_ci-- 5553aa9179Sopenharmony_ci2.27.0 5653aa9179Sopenharmony_ci 57