cURL / Mailing Lists / curl-library / Single Mail

curl-library

work-a-round for ugly Set-Cookie header lines (skip leading spaces)

From: Dirk Manske <dm_at_nettraffic.de>
Date: Sun, 14 Apr 2002 19:58:20 +0200

Dear libcurl developers,

may be following patch is not RFC conform but it helps with ugly Set-Cookie header
lines from ugly webservers like this:

  Set-Cookie: blah=fasel; path= /; expires=Saturday, 06-Sep-2014 23:50:08 GMT

Doh! A leading space in path, this sucks...

IMHO real spaces in cookie values should be encoded to %20, so this work-a-round
patch against 7.9.5 do it the right way:

----- snip
diff -u cookie.c.org cookie.c
--- cookie.c.org Wed Feb 27 08:38:04 2002
+++ cookie.c Sun Apr 14 19:48:29 2002
@@ -145,6 +145,8 @@
                        name, what)) {
           /* this is a <name>=<what> pair */

+ char *whatptr;
+
           /* Strip off trailing whitespace from the 'what' */
           int len=strlen(what);
           while(len && isspace((int)what[len-1])) {
@@ -152,15 +154,21 @@
             len--;
           }

+ /* Skip leading whitespace from the 'what' */
+ whatptr=what;
+ while(isspace(*whatptr)) {
+ whatptr++;
+ }
+
           if(strequal("path", name)) {
- co->path=strdup(what);
+ co->path=strdup(whatptr);
           }
           else if(strequal("domain", name)) {
- co->domain=strdup(what);
- co->field1= (what[0]=='.')?2:1;
+ co->domain=strdup(whatptr);
+ co->field1= (whatptr[0]=='.')?2:1;
           }
           else if(strequal("version", name)) {
- co->version=strdup(what);
+ co->version=strdup(whatptr);
           }
           else if(strequal("max-age", name)) {
             /* Defined in RFC2109:
@@ -172,17 +180,17 @@
                cookie should be discarded immediately.

              */
- co->maxage = strdup(what);
+ co->maxage = strdup(whatptr);
             co->expires =
               atoi((*co->maxage=='\"')?&co->maxage[1]:&co->maxage[0]) + now;
           }
           else if(strequal("expires", name)) {
- co->expirestr=strdup(what);
+ co->expirestr=strdup(whatptr);
             co->expires = curl_getdate(what, &now);
           }
           else if(!co->name) {
             co->name = strdup(name);
- co->value = strdup(what);
+ co->value = strdup(whatptr);
           }
           /*
             else this is the second (or more) name we don't know
----- snip

Coments?

Greeting from Hamburg,
Dirk Manske
Received on 2002-04-14