diff --git a/src/document/forms.h b/src/document/forms.h index 55934afe9..17449892f 100644 --- a/src/document/forms.h +++ b/src/document/forms.h @@ -86,6 +86,10 @@ struct form_control { unsigned char *id; /* used by scripts */ unsigned char *name; unsigned char *alt; + /* For FC_TEXT, FC_PASSWORD, and FC_TEXTAREA: @default_value + * is in the charset of the document. + * + * For FC_FILE: The parser does not set @default_value. */ unsigned char *default_value; int default_state; int size; diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index 844b40802..cabf9aa30 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -1809,18 +1809,6 @@ html_special_form_control(struct part *part, struct form_control *fc) fc->g_ctrl_num = renderer_context.g_ctrl_num++; - /* We don't want to recode hidden fields. */ - if (fc->type == FC_TEXT || fc->type == FC_PASSWORD || - fc->type == FC_TEXTAREA) { - unsigned char *dv = convert_string(renderer_context.convert_table, - fc->default_value, - strlen(fc->default_value), - part->document->options.cp, - CSM_FORM, NULL, NULL, NULL); - - if (dv) mem_free_set(&fc->default_value, dv); - } - if (list_empty(part->document->forms)) { /* No forms encountered yet, that means a homeless form * control. Generate a dummy form for those Flying diff --git a/src/ecmascript/see/form.c b/src/ecmascript/see/form.c index 9b2f5b9f6..abdb63173 100644 --- a/src/ecmascript/see/form.c +++ b/src/ecmascript/see/form.c @@ -200,6 +200,7 @@ input_get(struct SEE_interpreter *interp, struct SEE_object *o, } else if (p == s_defaultChecked) { SEE_SET_BOOLEAN(res, fc->default_state); } else if (p == s_defaultValue) { + /* FIXME (bug 805): convert from the charset of the document */ str = string_to_SEE_string(interp, fc->default_value); SEE_SET_STRING(res, str); } else if (p == s_disabled) { diff --git a/src/ecmascript/spidermonkey/form.c b/src/ecmascript/spidermonkey/form.c index 9436e1b93..2701f1478 100644 --- a/src/ecmascript/spidermonkey/form.c +++ b/src/ecmascript/spidermonkey/form.c @@ -206,6 +206,7 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) boolean_to_jsval(ctx, vp, fc->default_state); break; case JSP_INPUT_DEFAULT_VALUE: + /* FIXME (bug 805): convert from the charset of the document */ string_to_jsval(ctx, vp, fc->default_value); break; case JSP_INPUT_DISABLED: diff --git a/src/viewer/text/form.c b/src/viewer/text/form.c index 13e737c36..3b35391af 100644 --- a/src/viewer/text/form.c +++ b/src/viewer/text/form.c @@ -150,11 +150,24 @@ selected_item(struct terminal *term, void *item_, void *ses_) } static void -init_form_state(struct form_control *fc, struct form_state *fs) +init_form_state(struct document_view *doc_view, + struct form_control *fc, struct form_state *fs) { + struct terminal *term; + int doc_cp, viewer_cp; + assert(fc && fs); if_assert_failed return; + doc_cp = doc_view->document->cp; + term = doc_view->session->tab->term; +#ifdef CONFIG_UTF8 + if (term->utf8) + viewer_cp = get_cp_index("UTF-8"); + else +#endif + viewer_cp = get_opt_codepage_tree(term->spec, "charset"); + mem_free_set(&fs->value, NULL); switch (fc->type) { @@ -167,8 +180,14 @@ init_form_state(struct form_control *fc, struct form_state *fs) #endif /* CONFIG_FORMHIST */ /* fall through */ case FC_TEXTAREA: - if (fs->value == NULL) - fs->value = stracpy(fc->default_value); + if (fs->value == NULL) { + fs->value = convert_string( + get_translation_table(doc_cp, viewer_cp), + fc->default_value, + strlen(fc->default_value), + viewer_cp, CSM_FORM, + &fs->state, NULL, NULL); + } fs->state = fs->value ? strlen(fs->value) : 0; #ifdef CONFIG_UTF8 if (fc->type == FC_TEXTAREA) @@ -182,7 +201,12 @@ init_form_state(struct form_control *fc, struct form_state *fs) fs->vpos = 0; break; case FC_SELECT: - fs->value = stracpy(fc->default_value); + fs->value = convert_string( + get_translation_table(doc_cp, viewer_cp), + fc->default_value, + strlen(fc->default_value), + viewer_cp, CSM_FORM, + &fs->state, NULL, NULL); fs->state = fc->default_state; fixup_select_state(fc, fs); break; @@ -195,6 +219,7 @@ init_form_state(struct form_control *fc, struct form_state *fs) case FC_RESET: case FC_BUTTON: case FC_HIDDEN: + /* We don't want to recode hidden fields. */ fs->value = stracpy(fc->default_value); break; } @@ -236,7 +261,7 @@ find_form_state(struct document_view *doc_view, struct form_control *fc) fs->g_ctrl_num = fc->g_ctrl_num; fs->position = fc->position; fs->type = fc->type; - init_form_state(fc, fs); + init_form_state(doc_view, fc, fs); return fs; } @@ -1096,7 +1121,7 @@ do_reset_form(struct document_view *doc_view, struct form *form) foreach (fc, form->items) { struct form_state *fs = find_form_state(doc_view, fc); - if (fs) init_form_state(fc, fs); + if (fs) init_form_state(doc_view, fc, fs); } }