Branch: Tag:

2014-01-23

2014-01-23 10:30:47 by Henrik Grubbström (Grubba) <grubba@grubba.org>

HTTP: Added some DWIM for wide strings.

If the user has set a content-type with charset, the output charset
setting is ignored, and a wide string could be sent to the low-level
protocol code. Detect wide strings and force them to UTF-8 in this case.

5:   #include <config.h>   #include <module.h>   #include <module_constants.h> - constant cvs_version="$Id: prototypes.pike,v 1.237 2009/03/27 10:39:12 jonasw Exp $"; + constant cvs_version="$Id$";      #ifdef DAV_DEBUG   #define DAV_WERROR(X...) werror(X)
2616:    type += "; charset=" + charset;    }    -  heads["Content-Type"] = type; -  -  if (stringp (file->data)) +  if (stringp (file->data)) { +  if (String.width(file->data) > 8) { +  // Invalid charset header! +  // DWIM! +  eval_status["bad-charset"] = 1; +  file->data = string_to_utf8(file->data); +  type = (type/";")[0] + "; charset=utf-8"; +  }    file->len = sizeof (file->data); -  +  }    -  +  heads["Content-Type"] = type; +    #ifndef DISABLE_BYTE_RANGES    heads["Accept-Ranges"] = "bytes";   #endif