summaryrefslogtreecommitdiff
path: root/sys/src/cmd/webfs
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@centraldogma>2011-10-24 17:12:16 +0200
committercinap_lenrek <cinap_lenrek@centraldogma>2011-10-24 17:12:16 +0200
commitf6db05a45709ba792803b7d954833a96fb31e0e6 (patch)
treeb2f7d92704fe7ee4836fc414a7d8f676fb9ea34a /sys/src/cmd/webfs
parentc50bef06dda0c5186fa6653a834550ab03856fe5 (diff)
webfs: fix url escaping so it works with torrent
Diffstat (limited to 'sys/src/cmd/webfs')
-rw-r--r--sys/src/cmd/webfs/url.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/sys/src/cmd/webfs/url.c b/sys/src/cmd/webfs/url.c
index 5d808df37..8883432f6 100644
--- a/sys/src/cmd/webfs/url.c
+++ b/sys/src/cmd/webfs/url.c
@@ -711,9 +711,9 @@ postparse_http(Url *u)
u->http.page_spec = estrdup("/");
return 0;
}
- p = escapeurl(u->path, " \"<>#%\\");
+ p = escapeurl(u->path, "/");
if(u->query){
- q = escapeurl(u->query, " \"<>#%\\");
+ q = escapeurl(u->query, "&=");
u->http.page_spec = emalloc(strlen(p)+1+strlen(q)+1);
strcpy(u->http.page_spec, p);
strcat(u->http.page_spec, "?");
@@ -985,25 +985,22 @@ dhex(char c)
char*
escapeurl(char *s, char *special)
{
- int n;
- char *t, *u;
static char *hex = "0123456789abcdef";
+ char *t, *u;
- n = 0;
- for(t=s; *t; t++)
- if(*t <= 0x1F || *t >= 0x7F || strchr(special, *t))
- n++;
- u = emalloc(strlen(s)+2*n+1);
- t = u;
+ t = u = emalloc(strlen(s)*3+1);
for(; *s; s++){
- if(s[0] == '%' && isxdigit(s[1]) && isxdigit(s[2]))
+ if((s[0] == '%' && isxdigit(s[1]) && isxdigit(s[2])) ||
+ (*s >= '0' && *s <= '9') ||
+ (*s >= 'a' && *s <= 'z') ||
+ (*s >= 'A' && *s <= 'Z') ||
+ strchr(".-_~", *s) || strchr(special, *s))
*u++ = *s;
- else if(*s <= 0x1F || *s >= 0x7F || strchr(special, *s)){
+ else {
*u++ = '%';
*u++ = hex[(*s>>4)&0xF];
*u++ = hex[*s&0xF];
- }else
- *u++ = *s;
+ }
}
*u = '\0';
return t;
@@ -1012,7 +1009,8 @@ escapeurl(char *s, char *special)
char*
unescapeurl(char *s, char *special)
{
- char *r, *w, x;
+ char *r, *w;
+ Rune x;
s = estrdup(s);
for(r=w=s; x = *r; r++){