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

[document] pass charset to document_parse_text

This commit is contained in:
Witold Filipczyk 2023-05-16 20:08:36 +02:00
parent e470cf76dc
commit 40b825eadd
5 changed files with 9 additions and 7 deletions

View File

@ -17,17 +17,18 @@
#include "cache/cache.h"
#include "document/document.h"
#include "document/libdom/doc.h"
#include "intl/charsets.h"
#include "util/string.h"
void *
document_parse_text(char *data, size_t length)
document_parse_text(const char *charset, char *data, size_t length)
{
dom_hubbub_parser *parser = NULL;
dom_hubbub_error error;
dom_hubbub_parser_params params;
dom_document *doc;
params.enc = NULL;
params.enc = charset;
params.fix_enc = true;
params.enable_script = false;
params.msg = NULL;
@ -72,12 +73,13 @@ document_parse(struct document *document)
#endif
struct cache_entry *cached = document->cached;
struct fragment *f = get_cache_fragment(cached);
const char *charset = document->cp >= 0 ? get_cp_mime_name(document->cp) : "";
if (!f || !f->length) {
return NULL;
}
return document_parse_text(f->data, f->length);
return document_parse_text(charset, f->data, f->length);
}
void

View File

@ -8,7 +8,7 @@ extern "C" {
struct document;
struct string;
void *document_parse_text(char *data, size_t length);
void *document_parse_text(const char *charset, char *data, size_t length);
void *document_parse(struct document *document);
void free_document(void *doc);

View File

@ -40,7 +40,7 @@ mjs_implementation_createHTMLDocument(js_State *J)
add_html_to_string(&str, title, strlen(title));
add_to_string(&str, "</title></head><body></body></html>");
void *docu = document_parse_text(str.source, str.length);
void *docu = document_parse_text("utf-8", str.source, str.length);
done_string(&str);
mjs_push_document(J, docu);
}

View File

@ -58,7 +58,7 @@ js_implementation_createHTMLDocument(JSContext *ctx, JSValueConst this_val, int
add_html_to_string(&str, title, len);
add_to_string(&str, "</title></head><body></body></html>");
void *docu = document_parse_text(str.source, str.length);
void *docu = document_parse_text("utf-8", str.source, str.length);
done_string(&str);
JS_FreeCString(ctx, title);

View File

@ -78,7 +78,7 @@ implementation_createHTMLDocument(JSContext *ctx, unsigned int argc, JS::Value *
add_html_to_string(&str, title, strlen(title));
add_to_string(&str, "</title></head><body></body></html>");
void *docu = document_parse_text(str.source, str.length);
void *docu = document_parse_text("utf-8", str.source, str.length);
done_string(&str);
mem_free(title);