From f1f18ace456df1636daa3322713be25f9693a922 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 10 Nov 2022 13:25:37 +0100 Subject: [PATCH] [document] Try to set system charset. --- src/ecmascript/ecmascript.cpp | 2 +- src/protocol/common.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ecmascript/ecmascript.cpp b/src/ecmascript/ecmascript.cpp index 54f24253c..0140121a9 100644 --- a/src/ecmascript/ecmascript.cpp +++ b/src/ecmascript/ecmascript.cpp @@ -803,7 +803,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, get_cp_mime_name(document->cp), + xmlDoc* doc = htmlReadDoc((xmlChar*)str.source, NULL, NULL, 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/protocol/common.c b/src/protocol/common.c index 39dbad4a4..dde9292df 100644 --- a/src/protocol/common.c +++ b/src/protocol/common.c @@ -18,6 +18,7 @@ #include "elinks.h" #include "config/options.h" +#include "intl/charsets.h" #include "osdep/osdep.h" #include "protocol/common.h" #include "protocol/protocol.h" @@ -51,6 +52,7 @@ init_directory_listing(struct string *page, struct uri *uri) struct string location = NULL_STRING; const char *info; int local = (uri->protocol == PROTOCOL_FILE); + char *charset = straconcat("", (char *) NULL); if (!init_string(page) || !init_string(&dirpath) @@ -73,7 +75,13 @@ init_directory_listing(struct string *page, struct uri *uri) if (!local && !add_char_to_string(&location, '/')) goto out_of_memory; - if (!add_to_string(page, "\n")) + if (!add_to_string(page, "<html>\n<head>")) + goto out_of_memory; + + if (!add_to_string(page, charset)) + goto out_of_memory; + + if (!add_to_string(page, "<title>")) goto out_of_memory; if (!local && !add_html_to_string(page, location.source, location.length)) @@ -150,6 +158,7 @@ out_of_memory: done_string(&dirpath); done_string(&decoded); done_string(&location); + mem_free_if(charset); return page->length > 0 ? connection_state(S_OK)