1
0
Fork 0

[xml] Do not assume utf-8.

document_write4.html does not display utf-8
This commit is contained in:
Witold Filipczyk 2022-11-21 16:36:49 +01:00
parent c9fe1bf546
commit b9910df99d
3 changed files with 9 additions and 26 deletions

View File

@ -2585,6 +2585,7 @@ render_html_document(struct cache_entry *cached, struct document *document,
char *end;
struct string title;
struct string head;
int xml2;
assert(cached && document);
if_assert_failed return;
@ -2601,15 +2602,19 @@ render_html_document(struct cache_entry *cached, struct document *document,
put_chars_conv, line_break,
html_special);
if (!html_context) return;
#ifdef CONFIG_ECMASCRIPT
xml2 = !!document->dom;
#else
xml2 = 0;
#endif
renderer_context.g_ctrl_num = 0;
renderer_context.cached = cached;
renderer_context.convert_table = get_convert_table(head.source,
document->options.cp,
document->options.assume_cp,
xml2 ? get_cp_index("utf-8") : document->options.assume_cp,
&document->cp,
&document->cp_status,
document->options.hard_assume);
xml2 ? 1 : document->options.hard_assume);
#ifdef CONFIG_UTF8
html_context->options->utf8 = is_cp_utf8(document->options.cp);
#endif /* CONFIG_UTF8 */

View File

@ -354,26 +354,9 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str
if (!document->dom) {
return;
}
struct string head;
assert(cached && document);
if_assert_failed return;
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 (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);
}
xmlpp::Document *doc = (xmlpp::Document *)document->dom;
xmlpp::Element* root = (xmlpp::Element *)doc->get_root_node();
@ -381,7 +364,6 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str
struct string tt;
if (!init_string(&tt)) {
done_string(&head);
return;
}
std::map<int, xmlpp::Element *> *mapa = (std::map<int, xmlpp::Element *> *)document->element_map;
@ -397,9 +379,5 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str
buffer = &tt;
document->text = tt.source;
}
if (add_to_head) {
// mem_free_set(&cached->head, head.source);
}
render_html_document(cached, document, buffer);
}

View File

@ -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, "utf-8",
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);