From c9fe1bf5461ec823081d15c10a555aeaefd29bbf Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 20 Nov 2022 20:24:29 +0100 Subject: [PATCH] [xml] Force "utf-8" encoding. It is a step backwards. At least test cases for document.write don't crash. --- src/document/xml/renderer2.cpp | 18 +++++++++--------- src/ecmascript/ecmascript.cpp | 4 ++-- src/ecmascript/mujs/element.cpp | 2 +- src/ecmascript/quickjs/element.cpp | 2 +- src/ecmascript/spidermonkey/document.cpp | 9 +++++++-- src/ecmascript/spidermonkey/element.cpp | 2 +- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/document/xml/renderer2.cpp b/src/document/xml/renderer2.cpp index 42ef67ac..e32bc872 100644 --- a/src/document/xml/renderer2.cpp +++ b/src/document/xml/renderer2.cpp @@ -362,16 +362,16 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str if (!init_string(&head)) return; bool add_to_head = true; - if (cached->head) { - if (!strncmp(cached->head, "\r\nContent-Type: text/html; charset=utf-8\r\n", - sizeof("\r\nContent-Type: text/html; charset=utf-8\r\n") - 1)) { - add_to_head = false; - } - } +// if (cached->head) { +// if (!strncmp(cached->head, "\r\nContent-Type: text/html; charset=utf-8\r\n", +// sizeof("\r\nContent-Type: text/html; charset=utf-8\r\n") - 1)) { +// add_to_head = false; +// } +// } if (add_to_head) { - add_to_string(&head, "\r\nContent-Type: text/html; charset=utf-8\r\n"); - if (cached->head) add_to_string(&head, cached->head); +// add_to_string(&head, "\r\nContent-Type: text/html; charset=utf-8\r\n"); +// if (cached->head) add_to_string(&head, cached->head); } xmlpp::Document *doc = (xmlpp::Document *)document->dom; @@ -399,7 +399,7 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str } if (add_to_head) { - mem_free_set(&cached->head, head.source); +// mem_free_set(&cached->head, head.source); } render_html_document(cached, document, buffer); } diff --git a/src/ecmascript/ecmascript.cpp b/src/ecmascript/ecmascript.cpp index bb054f2c..9e0697c9 100644 --- a/src/ecmascript/ecmascript.cpp +++ b/src/ecmascript/ecmascript.cpp @@ -385,7 +385,7 @@ check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text) text += interpreter->writecode.source; text += ""; - xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, NULL, HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); + xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, "utf-8", HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); // Encapsulate raw libxml document in a libxml++ wrapper xmlpp::Document doc1(doc); @@ -889,7 +889,7 @@ document_parse(struct document *document) add_bytes_to_string(&str, f->data, f->length); // Parse HTML and create a DOM tree - xmlDoc* doc = htmlReadDoc((xmlChar*)str.source, NULL, NULL, + xmlDoc* doc = htmlReadDoc((xmlChar*)str.source, NULL, "utf-8", HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); // Encapsulate raw libxml document in a libxml++ wrapper xmlpp::Document *docu = new xmlpp::Document(doc); diff --git a/src/ecmascript/mujs/element.cpp b/src/ecmascript/mujs/element.cpp index 1613b080..5e5ac16d 100644 --- a/src/ecmascript/mujs/element.cpp +++ b/src/ecmascript/mujs/element.cpp @@ -924,7 +924,7 @@ mjs_element_set_property_innerHtml(js_State *J) text += val; text += ""; - xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, NULL, HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); + xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, "utf-8", HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); // Encapsulate raw libxml document in a libxml++ wrapper xmlpp::Document doc1(doc); diff --git a/src/ecmascript/quickjs/element.cpp b/src/ecmascript/quickjs/element.cpp index 709052e8..6bb8870f 100644 --- a/src/ecmascript/quickjs/element.cpp +++ b/src/ecmascript/quickjs/element.cpp @@ -928,7 +928,7 @@ js_element_set_property_innerHtml(JSContext *ctx, JSValueConst this_val, JSValue text += ""; JS_FreeCString(ctx, str); - xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, NULL, HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); + xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, "utf-8", HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); // Encapsulate raw libxml document in a libxml++ wrapper xmlpp::Document doc1(doc); diff --git a/src/ecmascript/spidermonkey/document.cpp b/src/ecmascript/spidermonkey/document.cpp index 9e8c79cc..9d47edab 100644 --- a/src/ecmascript/spidermonkey/document.cpp +++ b/src/ecmascript/spidermonkey/document.cpp @@ -1309,10 +1309,15 @@ document_write_do(JSContext *ctx, unsigned int argc, JS::Value *rval, int newlin { for (unsigned int i = 0; i < argc; ++i) { - jshandle_value_to_char_string(&interpreter->writecode, ctx, args[i]); + char *str = jsval_to_string(ctx, args[i]); + + if (str) { + add_to_string(&interpreter->writecode, str); + mem_free(str); + } } - if (newline) + if (newline) { add_to_string(&interpreter->writecode, "\n"); } diff --git a/src/ecmascript/spidermonkey/element.cpp b/src/ecmascript/spidermonkey/element.cpp index c9a939aa..846bf4db 100644 --- a/src/ecmascript/spidermonkey/element.cpp +++ b/src/ecmascript/spidermonkey/element.cpp @@ -2074,7 +2074,7 @@ element_set_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp) text += ""; mem_free_if(vv); - xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, NULL, HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); + xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, "utf-8", HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); // Encapsulate raw libxml document in a libxml++ wrapper xmlpp::Document doc1(doc);