diff --git a/src/ecmascript/ecmascript.c b/src/ecmascript/ecmascript.c index 2cd45cf21..f78d97cd6 100644 --- a/src/ecmascript/ecmascript.c +++ b/src/ecmascript/ecmascript.c @@ -16,12 +16,14 @@ #include "ecmascript/spidermonkey.h" #include "intl/gettext/libintl.h" #include "main/module.h" +#include "protocol/protocol.h" #include "protocol/uri.h" #include "session/session.h" #include "session/task.h" #include "terminal/terminal.h" #include "terminal/window.h" #include "util/conv.h" +#include "util/string.h" #include "viewer/text/view.h" /* current_frame() */ #include "viewer/text/form.h" /* <-ecmascript_reset_state() */ #include "viewer/text/vs.h" @@ -213,6 +215,40 @@ ecmascript_timeout_dialog(struct terminal *term, int max_exec_time) } +void +ecmascript_set_action(unsigned char **action, unsigned char *string) +{ + struct uri *protocol; + + trim_chars(string, ' ', NULL); + protocol = get_uri(string, URI_PROTOCOL); + + if (protocol) { /* full uri with protocol */ + done_uri(protocol); + mem_free_set(action, string); + } else { + if (string[0] == '/') { /* absolute uri */ + struct uri *uri = get_uri(*action, URI_HTTP_REFERRER_HOST); + + if (uri->protocol == PROTOCOL_FILE) { + mem_free_set(action, straconcat(struri(uri), string, NULL)); + } + else + mem_free_set(action, straconcat(struri(uri), string + 1, NULL)); + done_uri(uri); + mem_free(string); + } else { /* relative uri */ + unsigned char *last_slash = strrchr(*action, '/'); + unsigned char *new_action; + + if (last_slash) *(last_slash + 1) = '\0'; + new_action = straconcat(*action, string, NULL); + mem_free_set(action, new_action); + mem_free(string); + } + } +} + static struct module *ecmascript_modules[] = { #ifdef CONFIG_ECMASCRIPT_SEE &see_module, diff --git a/src/ecmascript/ecmascript.h b/src/ecmascript/ecmascript.h index 49775d411..119339e58 100644 --- a/src/ecmascript/ecmascript.h +++ b/src/ecmascript/ecmascript.h @@ -70,6 +70,7 @@ void ecmascript_protocol_handler(struct session *ses, struct uri *uri); void ecmascript_timeout_dialog(struct terminal *term, int max_exec_time); +void ecmascript_set_action(unsigned char **action, unsigned char *string); extern struct module ecmascript_module; diff --git a/src/ecmascript/see/form.c b/src/ecmascript/see/form.c index 2fc5ac58b..e2a95a970 100644 --- a/src/ecmascript/see/form.c +++ b/src/ecmascript/see/form.c @@ -860,13 +860,7 @@ form_put(struct SEE_interpreter *interp, struct SEE_object *o, if (p == s_action) { if (form->action) { - struct uri *uri = get_uri(form->action, URI_HTTP_REFERRER_HOST); - - if (uri) { - mem_free_set(&form->action, join_urls(uri, string)); - mem_free(string); - done_uri(uri); - } + ecmascript_set_action(&form->action, string); } else { mem_free_set(&form->action, string); } diff --git a/src/ecmascript/spidermonkey/form.c b/src/ecmascript/spidermonkey/form.c index e50384dca..8ce7c690f 100644 --- a/src/ecmascript/spidermonkey/form.c +++ b/src/ecmascript/spidermonkey/form.c @@ -735,16 +735,12 @@ form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) switch (JSVAL_TO_INT(id)) { case JSP_FORM_ACTION: + string = stracpy(jsval_to_string(ctx, vp)); if (form->action) { - struct uri *uri = get_uri(form->action, URI_HTTP_REFERRER_HOST); - - if (uri) { - mem_free_set(&form->action, join_urls(uri, jsval_to_string(ctx, vp))); - done_uri(uri); - break; - } + ecmascript_set_action(&form->action, string); + } else { + mem_free_set(&form->action, string); } - mem_free_set(&form->action, stracpy(jsval_to_string(ctx, vp))); break; case JSP_FORM_ENCODING: