Skip to content

Commit 79d417a

Browse files
chqrliebnoordhuis
authored andcommitted
Simplify and clarify URL quoting js_std_urlGet
1 parent ed49e0f commit 79d417a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

quickjs-libc.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValue this_val,
13371337
DynBuf header_buf_s, *header_buf = &header_buf_s;
13381338
char *buf;
13391339
size_t i, len;
1340-
int c, status;
1340+
int status;
13411341
JSValue response = JS_UNDEFINED, ret_obj;
13421342
JSValue options_obj;
13431343
FILE *f;
@@ -1365,17 +1365,20 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValue this_val,
13651365

13661366
js_std_dbuf_init(ctx, &cmd_buf);
13671367
dbuf_printf(&cmd_buf, "%s '", URL_GET_PROGRAM);
1368-
len = strlen(url);
1369-
for(i = 0; i < len; i++) {
1370-
switch (c = url[i]) {
1368+
for(i = 0; url[i] != '\0'; i++) {
1369+
unsigned char c = url[i];
1370+
switch (c) {
13711371
case '\'':
1372+
/* shell single quoted string does not support \' */
13721373
dbuf_putstr(&cmd_buf, "'\\''");
13731374
break;
13741375
case '[': case ']': case '{': case '}': case '\\':
1376+
/* prevent interpretation by curl as range or set specification */
13751377
dbuf_putc(&cmd_buf, '\\');
13761378
/* FALLTHROUGH */
13771379
default:
13781380
dbuf_putc(&cmd_buf, c);
1381+
break;
13791382
}
13801383
}
13811384
JS_FreeCString(ctx, url);

0 commit comments

Comments
 (0)