mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
ECMAScript: better handling of set action
This commit is contained in:
parent
b3acfd79f2
commit
dc075685ae
@ -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,
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user