diff --git a/src/document/css/apply.c b/src/document/css/apply.c index b4400edd..f39e84a0 100644 --- a/src/document/css/apply.c +++ b/src/document/css/apply.c @@ -186,7 +186,7 @@ examine_element(struct html_context *html_context, struct css_selector *base, process_found_selector(selector, CST_PSEUDO, base); } - code = get_attr_val(element->options, "class", html_context->options->cp); + code = get_attr_val(element->options, "class", html_context->doc_cp); if (code && seltype <= CST_CLASS) { unsigned char *class = code; @@ -203,7 +203,7 @@ examine_element(struct html_context *html_context, struct css_selector *base, } mem_free_if(code); - code = get_attr_val(element->options, "id", html_context->options->cp); + code = get_attr_val(element->options, "id", html_context->doc_cp); if (code && seltype <= CST_ID) { selector = find_css_selector(selectors, CST_ID, rel, code, -1); process_found_selector(selector, CST_ID, base); @@ -240,7 +240,7 @@ get_css_selector_for_element(struct html_context *html_context, DBG("Element %.*s applied.", element->namelen, element->name); #endif - code = get_attr_val(element->options, "style", html_context->options->cp); + code = get_attr_val(element->options, "style", html_context->doc_cp); if (code) { struct css_selector *stylesel; struct scanner scanner; diff --git a/src/document/html/internal.h b/src/document/html/internal.h index 89a56df1..419da38f 100644 --- a/src/document/html/internal.h +++ b/src/document/html/internal.h @@ -51,6 +51,10 @@ struct html_context { struct document_options *options; + /* doc_cp is the charset of the document, i.e. part->document->cp. + * It is copied here because part->document is NULL sometimes. */ + int doc_cp; + /* For: * html/parser/parse.c * html/parser/stack.c diff --git a/src/document/html/parser.c b/src/document/html/parser.c index ca25f8ed..8732de7e 100644 --- a/src/document/html/parser.c +++ b/src/document/html/parser.c @@ -57,7 +57,7 @@ get_color(struct html_context *html_context, unsigned char *a, if (!use_document_fg_colors(html_context->options)) return -1; - at = get_attr_val(a, c, html_context->options->cp); + at = get_attr_val(a, c, html_context->doc_cp); if (!at) return -1; r = decode_color(at, strlen(at), rgb); @@ -78,6 +78,8 @@ get_bgcolor(struct html_context *html_context, unsigned char *a, color_T *rgb) unsigned char * get_target(struct document_options *options, unsigned char *a) { + /* FIXME (bug 784): options->cp is the terminal charset; + * should use the document charset instead. */ unsigned char *v = get_attr_val(a, "target", options->cp); if (!v) return NULL; @@ -154,7 +156,7 @@ set_fragment_identifier(struct html_context *html_context, { unsigned char *id_attr; - id_attr = get_attr_val(attr_name, attr, html_context->options->cp); + id_attr = get_attr_val(attr_name, attr, html_context->doc_cp); if (id_attr) { html_context->special_f(html_context, SP_TAG, id_attr); @@ -235,7 +237,7 @@ html_focusable(struct html_context *html_context, unsigned char *a) if (!a) return; options = html_context->options; - cp = options->cp; + cp = html_context->doc_cp; accesskey = get_attr_val(a, "accesskey", cp); if (accesskey) { @@ -243,7 +245,7 @@ html_focusable(struct html_context *html_context, unsigned char *a) mem_free(accesskey); } - tabindex = get_num(a, "tabindex", options->cp); + tabindex = get_num(a, "tabindex", html_context->doc_cp); if (0 < tabindex && tabindex < 32767) { format.tabindex = (tabindex & 0x7fff) << 16; } @@ -450,6 +452,8 @@ look_for_map(unsigned char **pos, unsigned char *eof, struct uri *uri, if (strlcasecmp(name, namelen, "MAP", 3)) return 1; if (uri && uri->fragment) { + /* FIXME (bug 784): options->cp is the terminal charset; + * should use the document charset instead. */ al = get_attr_val(attr, "name", options->cp); if (!al) return 1; @@ -548,6 +552,8 @@ look_for_link(unsigned char **pos, unsigned char *eof, struct menu_item **menu, if (*pos >= eof) return 0; } else if (!strlcasecmp(name, namelen, "AREA", 4)) { + /* FIXME (bug 784): options->cp is the terminal charset; + * should use the document charset instead. */ unsigned char *alt = get_attr_val(attr, "alt", options->cp); if (alt) { @@ -582,6 +588,8 @@ look_for_link(unsigned char **pos, unsigned char *eof, struct menu_item **menu, return 1; } + /* FIXME (bug 784): options->cp is the terminal charset; + * should use the document charset instead. */ href = get_url_val(attr, "href", options->cp); if (!href) { mem_free_if(label); @@ -741,6 +749,9 @@ done_html_parser_state(struct html_context *html_context, } +/* This function does not set html_context.doc_cp = document.cp, + * because it does not know the document, and because the codepage has + * not even been decided when it is called. */ struct html_context * init_html_parser(struct uri *uri, struct document_options *options, unsigned char *start, unsigned char *end, diff --git a/src/document/html/parser/forms.c b/src/document/html/parser/forms.c index cf8581b2..581adb21 100644 --- a/src/document/html/parser/forms.c +++ b/src/document/html/parser/forms.c @@ -50,13 +50,13 @@ html_form(struct html_context *html_context, unsigned char *a, form->method = FORM_METHOD_GET; form->form_num = a - html_context->startf; - al = get_attr_val(a, "method", html_context->options->cp); + al = get_attr_val(a, "method", html_context->doc_cp); if (al) { if (!strcasecmp(al, "post")) { unsigned char *enctype; enctype = get_attr_val(a, "enctype", - html_context->options->cp); + html_context->doc_cp); form->method = FORM_METHOD_POST; if (enctype) { @@ -69,11 +69,11 @@ html_form(struct html_context *html_context, unsigned char *a, } mem_free(al); } - form->onsubmit = get_attr_val(a, "onsubmit", html_context->options->cp); - al = get_attr_val(a, "name", html_context->options->cp); + form->onsubmit = get_attr_val(a, "onsubmit", html_context->doc_cp); + al = get_attr_val(a, "name", html_context->doc_cp); if (al) form->name = al; - al = get_attr_val(a, "action", html_context->options->cp); + al = get_attr_val(a, "action", html_context->doc_cp); /* The HTML specification at * http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.3 states * that the behavior of an empty action attribute should be undefined. @@ -114,10 +114,10 @@ html_form(struct html_context *html_context, unsigned char *a, static int get_form_mode(struct html_context *html_context, unsigned char *attr) { - if (has_attr(attr, "disabled", html_context->options->cp)) + if (has_attr(attr, "disabled", html_context->doc_cp)) return FORM_MODE_DISABLED; - if (has_attr(attr, "readonly", html_context->options->cp)) + if (has_attr(attr, "readonly", html_context->doc_cp)) return FORM_MODE_READONLY; return FORM_MODE_NORMAL; @@ -146,8 +146,7 @@ html_button(struct html_context *html_context, unsigned char *a, unsigned char *al; struct form_control *fc; enum form_type type = FC_SUBMIT; - int cp = (html_context->part && html_context->part->document) ? - html_context->part->document->cp : html_context->options->cp; + int cp = html_context->doc_cp; html_focusable(html_context, a); @@ -197,7 +196,7 @@ html_input_format(struct html_context *html_context, unsigned char *a, html_focusable(html_context, a); format.form = fc; if (format.title) mem_free(format.title); - format.title = get_attr_val(a, "title", html_context->options->cp); + format.title = get_attr_val(a, "title", html_context->doc_cp); switch (fc->type) { case FC_TEXT: case FC_PASSWORD: @@ -223,10 +222,10 @@ html_input_format(struct html_context *html_context, unsigned char *a, unsigned char *al; mem_free_set(&format.image, NULL); - al = get_url_val(a, "src", html_context->options->cp); + al = get_url_val(a, "src", html_context->doc_cp); if (!al) al = get_url_val(a, "dynsrc", - html_context->options->cp); + html_context->doc_cp); if (al) { format.image = join_urls(html_context->base_href, al); mem_free(al); @@ -267,8 +266,7 @@ html_input(struct html_context *html_context, unsigned char *a, { unsigned char *al; struct form_control *fc; - int cp = (html_context->part && html_context->part->document) ? - html_context->part->document->cp : html_context->options->cp; + int cp = html_context->doc_cp; fc = init_form_control(FC_TEXT, a, html_context); if (!fc) return; @@ -421,18 +419,18 @@ abort: if (!closing_tag) { unsigned char *value, *label; - if (has_attr(t_attr, "disabled", html_context->options->cp)) + if (has_attr(t_attr, "disabled", html_context->doc_cp)) goto see; if (preselect == -1 - && has_attr(t_attr, "selected", html_context->options->cp)) + && has_attr(t_attr, "selected", html_context->doc_cp)) preselect = order; - value = get_attr_val(t_attr, "value", html_context->options->cp); + value = get_attr_val(t_attr, "value", html_context->doc_cp); if (!mem_align_alloc(&values, order, order + 1, 0xFF)) goto abort; values[order++] = value; - label = get_attr_val(t_attr, "label", html_context->options->cp); + label = get_attr_val(t_attr, "label", html_context->doc_cp); if (label) new_menu_item(&lnk_menu, label, order - 1, 0); if (!value || !label) { init_string(&lbl); @@ -452,7 +450,7 @@ abort: if (!closing_tag) { unsigned char *label; - label = get_attr_val(t_attr, "label", html_context->options->cp); + label = get_attr_val(t_attr, "label", html_context->doc_cp); if (!label) { label = stracpy(""); @@ -479,9 +477,9 @@ end_parse: goto abort; } - fc->id = get_attr_val(attr, "id", html_context->options->cp); - fc->name = get_attr_val(attr, "name", html_context->options->cp); - fc->onchange = get_attr_val(attr, "onchange", html_context->options->cp); + fc->id = get_attr_val(attr, "id", html_context->doc_cp); + fc->name = get_attr_val(attr, "name", html_context->doc_cp); + fc->onchange = get_attr_val(attr, "onchange", html_context->doc_cp); fc->default_state = preselect < 0 ? 0 : preselect; fc->default_value = order ? stracpy(values[fc->default_state]) : stracpy(""); fc->nvalues = order; @@ -521,13 +519,13 @@ do_html_select_multiple(struct html_context *html_context, unsigned char *a, unsigned char *html, unsigned char *eof, unsigned char **end) { - unsigned char *al = get_attr_val(a, "name", html_context->options->cp); + unsigned char *al = get_attr_val(a, "name", html_context->doc_cp); if (!al) return; html_focusable(html_context, a); html_top->type = ELEMENT_DONT_KILL; mem_free_set(&format.select, al); - format.select_disabled = has_attr(a, "disabled", html_context->options->cp) + format.select_disabled = has_attr(a, "disabled", html_context->doc_cp) ? FORM_MODE_DISABLED : FORM_MODE_NORMAL; } @@ -536,7 +534,7 @@ void html_select(struct html_context *html_context, unsigned char *a, unsigned char *html, unsigned char *eof, unsigned char **end) { - if (has_attr(a, "multiple", html_context->options->cp)) + if (has_attr(a, "multiple", html_context->doc_cp)) do_html_select_multiple(html_context, a, html, eof, end); else do_html_select(a, html, eof, end, html_context); @@ -552,7 +550,7 @@ html_option(struct html_context *html_context, unsigned char *a, if (!format.select) return; - val = get_attr_val(a, "value", html_context->options->cp); + val = get_attr_val(a, "value", html_context->doc_cp); if (!val) { struct string str; unsigned char *p, *r; @@ -603,11 +601,11 @@ end_parse: return; } - fc->id = get_attr_val(a, "id", html_context->options->cp); + fc->id = get_attr_val(a, "id", html_context->doc_cp); fc->name = null_or_stracpy(format.select); fc->default_value = val; - fc->default_state = has_attr(a, "selected", html_context->options->cp); - fc->mode = has_attr(a, "disabled", html_context->options->cp) + fc->default_state = has_attr(a, "selected", html_context->doc_cp); + fc->mode = has_attr(a, "disabled", html_context->doc_cp) ? FORM_MODE_DISABLED : format.select_disabled; @@ -649,8 +647,8 @@ pp: fc = init_form_control(FC_TEXTAREA, attr, html_context); if (!fc) return; - fc->id = get_attr_val(attr, "id", html_context->options->cp); - fc->name = get_attr_val(attr, "name", html_context->options->cp); + fc->id = get_attr_val(attr, "id", html_context->doc_cp); + fc->name = get_attr_val(attr, "name", html_context->doc_cp); fc->default_value = memacpy(html, p - html); for (p = fc->default_value; p && p[0]; p++) { /* FIXME: We don't cope well with entities here. Bugzilla uses @@ -667,7 +665,7 @@ pp: } } - cols = get_num(attr, "cols", html_context->options->cp); + cols = get_num(attr, "cols", html_context->doc_cp); if (cols <= 0) cols = html_context->options->default_form_input_size; cols++; /* Add 1 column, other browsers may have different @@ -676,14 +674,14 @@ pp: cols = html_context->options->box.width; fc->cols = cols; - rows = get_num(attr, "rows", html_context->options->cp); + rows = get_num(attr, "rows", html_context->doc_cp); if (rows <= 0) rows = 1; if (rows > html_context->options->box.height) rows = html_context->options->box.height; fc->rows = rows; html_context->options->needs_height = 1; - wrap_attr = get_attr_val(attr, "wrap", html_context->options->cp); + wrap_attr = get_attr_val(attr, "wrap", html_context->doc_cp); if (wrap_attr) { if (!strcasecmp(wrap_attr, "hard") || !strcasecmp(wrap_attr, "physical")) { @@ -697,14 +695,14 @@ pp: } mem_free(wrap_attr); - } else if (has_attr(attr, "nowrap", html_context->options->cp)) { + } else if (has_attr(attr, "nowrap", html_context->doc_cp)) { fc->wrap = FORM_WRAP_NONE; } else { fc->wrap = FORM_WRAP_SOFT; } - fc->maxlength = get_num(attr, "maxlength", html_context->options->cp); + fc->maxlength = get_num(attr, "maxlength", html_context->doc_cp); if (fc->maxlength == -1) fc->maxlength = INT_MAX; if (rows > 1) ln_break(html_context, 1); diff --git a/src/document/html/parser/general.c b/src/document/html/parser/general.c index 2998a312..b28506e4 100644 --- a/src/document/html/parser/general.c +++ b/src/document/html/parser/general.c @@ -136,7 +136,7 @@ void html_font(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { - unsigned char *al = get_attr_val(a, "size", html_context->options->cp); + unsigned char *al = get_attr_val(a, "size", html_context->doc_cp); if (al) { int p = 0; @@ -223,7 +223,7 @@ html_script(struct html_context *html_context, unsigned char *a, /* Ref: * http://www.ietf.org/internet-drafts/draft-hoehrmann-script-types-03.txt */ - type = get_attr_val(a, "type", html_context->options->cp); + type = get_attr_val(a, "type", html_context->doc_cp); if (type) { unsigned char *pos = type; @@ -265,7 +265,7 @@ not_processed: * language attribute can be JavaScript with optional version digits * postfixed (like: ``JavaScript1.1''). * That attribute is deprecated in favor of type by HTML 4.01 */ - language = get_attr_val(a, "language", html_context->options->cp); + language = get_attr_val(a, "language", html_context->doc_cp); if (language) { int languagelen = strlen(language); @@ -280,7 +280,7 @@ not_processed: } if (html_context->part->document - && (src = get_attr_val(a, "src", html_context->options->cp))) { + && (src = get_attr_val(a, "src", html_context->doc_cp))) { /* External reference. */ unsigned char *import_url; @@ -479,7 +479,7 @@ void html_linebrk(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { - unsigned char *al = get_attr_val(a, "align", html_context->options->cp); + unsigned char *al = get_attr_val(a, "align", html_context->doc_cp); if (al) { if (!strcasecmp(al, "left")) par_format.align = ALIGN_LEFT; @@ -632,7 +632,7 @@ html_hr(struct html_context *html_context, unsigned char *a, { int i/* = par_format.width - 10*/; unsigned char r = (unsigned char) BORDER_DHLINE; - int q = get_num(a, "size", html_context->options->cp); + int q = get_num(a, "size", html_context->doc_cp); if (q >= 0 && q < 2) r = (unsigned char) BORDER_SHLINE; html_stack_dup(html_context, ELEMENT_KILLABLE); @@ -714,7 +714,7 @@ html_base(struct html_context *html_context, unsigned char *a, { unsigned char *al; - al = get_url_val(a, "href", html_context->options->cp); + al = get_url_val(a, "href", html_context->doc_cp); if (al) { unsigned char *base = join_urls(html_context->base_href, al); struct uri *uri = base ? get_uri(base, 0) : NULL; @@ -743,7 +743,7 @@ html_ul(struct html_context *html_context, unsigned char *a, par_format.list_number = 0; par_format.flags = P_STAR; - al = get_attr_val(a, "type", html_context->options->cp); + al = get_attr_val(a, "type", html_context->doc_cp); if (al) { if (!strcasecmp(al, "disc") || !strcasecmp(al, "circle")) par_format.flags = P_O; @@ -767,12 +767,12 @@ html_ol(struct html_context *html_context, unsigned char *a, int st; par_format.list_level++; - st = get_num(a, "start", html_context->options->cp); + st = get_num(a, "start", html_context->doc_cp); if (st == -1) st = 1; par_format.list_number = st; par_format.flags = P_NUMBER; - al = get_attr_val(a, "type", html_context->options->cp); + al = get_attr_val(a, "type", html_context->doc_cp); if (al) { if (*al && !al[1]) { if (*al == '1') par_format.flags = P_NUMBER; @@ -875,7 +875,7 @@ html_li(struct html_context *html_context, unsigned char *a, unsigned char n[32]; int nlen; int t = par_format.flags & P_LISTMASK; - int s = get_num(a, "value", html_context->options->cp); + int s = get_num(a, "value", html_context->doc_cp); if (s != -1) par_format.list_number = s; @@ -932,7 +932,7 @@ html_dl(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { par_format.flags &= ~P_COMPACT; - if (has_attr(a, "compact", html_context->options->cp)) + if (has_attr(a, "compact", html_context->doc_cp)) par_format.flags |= P_COMPACT; if (par_format.list_level) par_format.leftmargin += 5; par_format.list_level++; @@ -954,7 +954,7 @@ html_dt(struct html_context *html_context, unsigned char *a, par_format.align = ALIGN_LEFT; par_format.leftmargin = par_format.dd_margin; if (!(par_format.flags & P_COMPACT) - && !has_attr(a, "compact", html_context->options->cp)) + && !has_attr(a, "compact", html_context->doc_cp)) ln_break(html_context, 2); } @@ -995,7 +995,7 @@ html_frame(struct html_context *html_context, unsigned char *a, { unsigned char *name, *src, *url; - src = get_url_val(a, "src", html_context->options->cp); + src = get_url_val(a, "src", html_context->doc_cp); if (!src) { url = stracpy("about:blank"); } else { @@ -1004,7 +1004,7 @@ html_frame(struct html_context *html_context, unsigned char *a, } if (!url) return; - name = get_attr_val(a, "name", html_context->options->cp); + name = get_attr_val(a, "name", html_context->doc_cp); if (!name) { name = stracpy(url); } else if (!name[0]) { @@ -1048,13 +1048,13 @@ html_frameset(struct html_context *html_context, unsigned char *a, || !html_context->special_f(html_context, SP_USED, NULL)) return; - cols = get_attr_val(a, "cols", html_context->options->cp); + cols = get_attr_val(a, "cols", html_context->doc_cp); if (!cols) { cols = stracpy("100%"); if (!cols) return; } - rows = get_attr_val(a, "rows", html_context->options->cp); + rows = get_attr_val(a, "rows", html_context->doc_cp); if (!rows) { rows = stracpy("100%"); if (!rows) { diff --git a/src/document/html/parser/link.c b/src/document/html/parser/link.c index 1c7911ff..1b774c2a 100644 --- a/src/document/html/parser/link.c +++ b/src/document/html/parser/link.c @@ -45,7 +45,7 @@ html_a(struct html_context *html_context, unsigned char *a, { unsigned char *href; - href = get_url_val(a, "href", html_context->options->cp); + href = get_url_val(a, "href", html_context->doc_cp); if (href) { unsigned char *target; @@ -84,7 +84,7 @@ html_a(struct html_context *html_context, unsigned char *a, } mem_free_set(&format.title, - get_attr_val(a, "title", html_context->options->cp)); + get_attr_val(a, "title", html_context->doc_cp)); html_focusable(html_context, a); @@ -215,8 +215,6 @@ html_img_do(unsigned char *a, unsigned char *object_src, unsigned char *usemap_attr; struct document_options *options = html_context->options; int display_style = options->image_link.display_style; - int cp = (html_context->part && html_context->part->document) ? - html_context->part->document->cp : html_context->options->cp; /* Note about display_style: * 0 means always display IMG @@ -224,7 +222,7 @@ html_img_do(unsigned char *a, unsigned char *object_src, * 2 means display alt/title attribute if possible, IMG if not * 3 means display alt/title attribute if possible, filename if not */ - usemap_attr = get_attr_val(a, "usemap", options->cp); + usemap_attr = get_attr_val(a, "usemap", html_context->doc_cp); if (usemap_attr) { unsigned char *joined_urls = join_urls(html_context->base_href, usemap_attr); @@ -245,13 +243,13 @@ html_img_do(unsigned char *a, unsigned char *object_src, } ismap = format.link - && has_attr(a, "ismap", options->cp) + && has_attr(a, "ismap", html_context->doc_cp) && !usemap; if (display_style == 2 || display_style == 3) { - label = get_attr_val(a, "alt", cp); + label = get_attr_val(a, "alt", html_context->doc_cp); if (!label) - label = get_attr_val(a, "title", options->cp); + label = get_attr_val(a, "title", html_context->doc_cp); /* Little hack to preserve rendering of [ ], in directories listing, * but we still want to drop extra spaces in alt or title attribute @@ -260,8 +258,8 @@ html_img_do(unsigned char *a, unsigned char *object_src, } src = null_or_stracpy(object_src); - if (!src) src = get_url_val(a, "src", options->cp); - if (!src) src = get_url_val(a, "dynsrc", options->cp); + if (!src) src = get_url_val(a, "src", html_context->doc_cp); + if (!src) src = get_url_val(a, "dynsrc", html_context->doc_cp); /* If we have no label yet (no title or alt), so * just use default ones, or image filename. */ @@ -322,7 +320,7 @@ html_img_do(unsigned char *a, unsigned char *object_src, format.image = join_urls(html_context->base_href, src); } - format.title = get_attr_val(a, "title", options->cp); + format.title = get_attr_val(a, "title", html_context->doc_cp); if (ismap) { unsigned char *new_link; @@ -382,10 +380,10 @@ html_applet(struct html_context *html_context, unsigned char *a, { unsigned char *code, *alt; - code = get_url_val(a, "code", html_context->options->cp); + code = get_url_val(a, "code", html_context->doc_cp); if (!code) return; - alt = get_attr_val(a, "alt", html_context->options->cp); + alt = get_attr_val(a, "alt", html_context->doc_cp); html_focusable(html_context, a); @@ -408,11 +406,11 @@ html_iframe_do(unsigned char *a, unsigned char *object_src, unsigned char *name, *url = NULL; url = null_or_stracpy(object_src); - if (!url) url = get_url_val(a, "src", html_context->options->cp); + if (!url) url = get_url_val(a, "src", html_context->doc_cp); if (!url) return; - name = get_attr_val(a, "name", html_context->options->cp); - if (!name) name = get_attr_val(a, "id", html_context->options->cp); + name = get_attr_val(a, "name", html_context->doc_cp); + if (!name) name = get_attr_val(a, "id", html_context->doc_cp); if (!name) name = stracpy(""); if (!name) { mem_free(url); @@ -450,11 +448,11 @@ html_object(struct html_context *html_context, unsigned char *a, * this, which is anyway in the spirit of element, unifying * and