mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-22 13:48:11 +08:00
Simplify and clarify URL quoting js_std_urlGet
This commit is contained in:
parent
636c946531
commit
92e339d14f
@ -1335,7 +1335,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
|
|||||||
DynBuf header_buf_s, *header_buf = &header_buf_s;
|
DynBuf header_buf_s, *header_buf = &header_buf_s;
|
||||||
char *buf;
|
char *buf;
|
||||||
size_t i, len;
|
size_t i, len;
|
||||||
int c, status;
|
int status;
|
||||||
JSValue response = JS_UNDEFINED, ret_obj;
|
JSValue response = JS_UNDEFINED, ret_obj;
|
||||||
JSValueConst options_obj;
|
JSValueConst options_obj;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
@ -1363,17 +1363,20 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
|
|||||||
|
|
||||||
js_std_dbuf_init(ctx, &cmd_buf);
|
js_std_dbuf_init(ctx, &cmd_buf);
|
||||||
dbuf_printf(&cmd_buf, "%s '", URL_GET_PROGRAM);
|
dbuf_printf(&cmd_buf, "%s '", URL_GET_PROGRAM);
|
||||||
len = strlen(url);
|
for(i = 0; url[i] != '\0'; i++) {
|
||||||
for(i = 0; i < len; i++) {
|
unsigned char c = url[i];
|
||||||
switch (c = url[i]) {
|
switch (c) {
|
||||||
case '\'':
|
case '\'':
|
||||||
|
/* shell single quoted string does not support \' */
|
||||||
dbuf_putstr(&cmd_buf, "'\\''");
|
dbuf_putstr(&cmd_buf, "'\\''");
|
||||||
break;
|
break;
|
||||||
case '[': case ']': case '{': case '}': case '\\':
|
case '[': case ']': case '{': case '}': case '\\':
|
||||||
|
/* prevent interpretation by curl as range or set specification */
|
||||||
dbuf_putc(&cmd_buf, '\\');
|
dbuf_putc(&cmd_buf, '\\');
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
default:
|
default:
|
||||||
dbuf_putc(&cmd_buf, c);
|
dbuf_putc(&cmd_buf, c);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JS_FreeCString(ctx, url);
|
JS_FreeCString(ctx, url);
|
||||||
|
Loading…
Reference in New Issue
Block a user