`url` (http / https) as scheme://host[:port]/path -- the user info, the * query and the fragment dropped, so no credential or token reaches the * graph; NULL when it is not one, or its host is unknown. */
| 2048 | * query and the fragment dropped, so no credential or token reaches the |
| 2049 | * graph; NULL when it is not one, or its host is unknown. */ |
| 2050 | static const char *sh_url_norm(CBMArena *a, const char *url) { |
| 2051 | const char *scheme_end = strstr(url, "://"); |
| 2052 | if (!scheme_end || (strncmp(url, "http://", strlen("http://")) != 0 && |
| 2053 | strncmp(url, "https://", strlen("https://")) != 0)) { |
| 2054 | return NULL; |
| 2055 | } |
| 2056 | const char *auth = scheme_end + strlen("://"); |
| 2057 | size_t al = strcspn(auth, "/?#"); |
| 2058 | const char *at = NULL; |
| 2059 | for (size_t i = 0; i < al; i++) { |
| 2060 | if (auth[i] == '@') { |
| 2061 | at = auth + i; |
| 2062 | } |
| 2063 | } |
| 2064 | const char *host = at ? at + SKIP_ONE : auth; |
| 2065 | size_t hl = (size_t)(auth + al - host); |
| 2066 | const char *h = hl ? cbm_arena_strndup(a, host, hl) : NULL; |
| 2067 | if (!h || strpbrk(h, "$`{}\"' \t\\")) { |
| 2068 | return NULL; |
| 2069 | } |
| 2070 | const char *path = auth + al; |
| 2071 | size_t pl = strcspn(path, "?#"); |
| 2072 | return cbm_arena_sprintf(a, "%.*s%.*s%.*s", (int)(auth - url), url, (int)hl, host, |
| 2073 | pl ? (int)pl : SKIP_ONE, pl ? path : "/"); |
| 2074 | } |
| 2075 | |
| 2076 | /* Skip one expansion at p (`${...}`, `$(...)`, `$NAME`, a backquoted |
| 2077 | * command); returns the byte after it. */ |
no test coverage detected