curl / wget with a URL the script states (constant words): an HTTP * request to it, from the command's function. */
| 2189 | /* curl / wget with a URL the script states (constant words): an HTTP |
| 2190 | * request to it, from the command's function. */ |
| 2191 | static void sh_http(sh_t *s, TSNode cmd, const sh_argv_t *a) { |
| 2192 | int p = sh_program(s, a); |
| 2193 | const char *prog = p >= 0 && a->v[p] ? sh_basename(a->v[p]) : NULL; |
| 2194 | if (!prog || (strcmp(prog, "curl") != 0 && strcmp(prog, "wget") != 0)) { |
| 2195 | return; |
| 2196 | } |
| 2197 | const char *via = strcmp(prog, "curl") == 0 ? "curl" : "wget"; |
| 2198 | const char *method = sh_http_method(a, p + SKIP_ONE); |
| 2199 | for (int i = p + SKIP_ONE; i < a->n; i++) { |
| 2200 | /* arguments that touch in the source are one shell word, which |
| 2201 | * tree-sitter-bash may split around an expansion */ |
| 2202 | int j = i; |
| 2203 | while (j + SKIP_ONE < a->n && |
| 2204 | a->span[PAIR_LEN * (j + SKIP_ONE)] == a->span[PAIR_LEN * j + SKIP_ONE]) { |
| 2205 | j++; |
| 2206 | } |
| 2207 | bool url_option = |
| 2208 | i > p + SKIP_ONE && a->v[i - SKIP_ONE] && sh_http_url_option(a->v[i - SKIP_ONE]); |
| 2209 | sh_str_t word = {0}; |
| 2210 | for (int k = i; k <= j; k++) { |
| 2211 | sh_str_add(s->a, &word, a->v[k], a->v[k] ? strlen(a->v[k]) : 0); |
| 2212 | } |
| 2213 | const char *w = sh_str_done(&word); |
| 2214 | /* a `$` left in an evaluated word is an expansion the grammar took |
| 2215 | * for text (`$OS-$ARCH.tgz`): no value, so the template */ |
| 2216 | const char *url = url_option ? NULL |
| 2217 | : w && !strpbrk(w, "$`") ? sh_url_norm(s->a, w) |
| 2218 | : sh_url_template(s, a, i); |
| 2219 | if (url) { |
| 2220 | sh_hit_push(s, cmd, (sh_hit_t){.via = via, .ext = url, .path = method, .http = true}); |
| 2221 | } |
| 2222 | i = j; |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | /* ── Statements ────────────────────────────────────────────────────── */ |
| 2227 |
no test coverage detected