# --- T2-COPYRIGHT-BEGIN --- # t2/package/*/fget/http-urlencode.patch # Copyright (C) 2024 - 2026 The T2 SDE Project # SPDX-License-Identifier: GPL-2.0 or patched project license # --- T2-COPYRIGHT-END --- --- ./fget.c.vanilla 2024-03-20 13:26:53.078325517 +0100 +++ ./fget.c 2024-03-20 13:38:30.234325849 +0100 @@ -112,10 +112,21 @@ static stralloc auth = {0}; static stralloc b64 = {0}; static char base64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + static char hex[]="0123456789ABCDEF"; char buf[20]; stralloc_copys(request,"GET "); - stralloc_cats(request,path); + // url escape + for (unsigned char c; *path; path++) { + c = *path; + if (isalnum(c) || (c >= '-' && c <= '/') || (c == '~')) { + stralloc_append(request,path); + } else { + stralloc_append(request,"%"); + stralloc_append(request,hex+(c>>4)); + stralloc_append(request,hex+(c&0xf)); + } + } stralloc_cats(request," HTTP/1.0\r\nHost: "); stralloc_cat(request,&host); stralloc_cats(request,":");