1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[xml] Force "utf-8" encoding.

It is a step backwards. At least test cases for document.write don't crash.
This commit is contained in:
Witold Filipczyk 2022-11-20 20:24:29 +01:00
parent df28d4345b
commit c9fe1bf546
6 changed files with 21 additions and 16 deletions

View File

@ -362,16 +362,16 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str
if (!init_string(&head)) return; if (!init_string(&head)) return;
bool add_to_head = true; bool add_to_head = true;
if (cached->head) { // if (cached->head) {
if (!strncmp(cached->head, "\r\nContent-Type: text/html; charset=utf-8\r\n", // 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)) { // sizeof("\r\nContent-Type: text/html; charset=utf-8\r\n") - 1)) {
add_to_head = false; // add_to_head = false;
} // }
} // }
if (add_to_head) { if (add_to_head) {
add_to_string(&head, "\r\nContent-Type: text/html; charset=utf-8\r\n"); // add_to_string(&head, "\r\nContent-Type: text/html; charset=utf-8\r\n");
if (cached->head) add_to_string(&head, cached->head); // if (cached->head) add_to_string(&head, cached->head);
} }
xmlpp::Document *doc = (xmlpp::Document *)document->dom; 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) { if (add_to_head) {
mem_free_set(&cached->head, head.source); // mem_free_set(&cached->head, head.source);
} }
render_html_document(cached, document, buffer); render_html_document(cached, document, buffer);
} }

View File

@ -385,7 +385,7 @@ check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text)
text += interpreter->writecode.source; text += interpreter->writecode.source;
text += "</root>"; text += "</root>";
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 // Encapsulate raw libxml document in a libxml++ wrapper
xmlpp::Document doc1(doc); xmlpp::Document doc1(doc);
@ -889,7 +889,7 @@ document_parse(struct document *document)
add_bytes_to_string(&str, f->data, f->length); add_bytes_to_string(&str, f->data, f->length);
// Parse HTML and create a DOM tree // 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); HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING);
// Encapsulate raw libxml document in a libxml++ wrapper // Encapsulate raw libxml document in a libxml++ wrapper
xmlpp::Document *docu = new xmlpp::Document(doc); xmlpp::Document *docu = new xmlpp::Document(doc);

View File

@ -924,7 +924,7 @@ mjs_element_set_property_innerHtml(js_State *J)
text += val; text += val;
text += "</root>"; text += "</root>";
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 // Encapsulate raw libxml document in a libxml++ wrapper
xmlpp::Document doc1(doc); xmlpp::Document doc1(doc);

View File

@ -928,7 +928,7 @@ js_element_set_property_innerHtml(JSContext *ctx, JSValueConst this_val, JSValue
text += "</root>"; text += "</root>";
JS_FreeCString(ctx, str); 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 // Encapsulate raw libxml document in a libxml++ wrapper
xmlpp::Document doc1(doc); xmlpp::Document doc1(doc);

View File

@ -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) 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"); add_to_string(&interpreter->writecode, "\n");
} }

View File

@ -2074,7 +2074,7 @@ element_set_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp)
text += "</root>"; text += "</root>";
mem_free_if(vv); 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 // Encapsulate raw libxml document in a libxml++ wrapper
xmlpp::Document doc1(doc); xmlpp::Document doc1(doc);