Skip to content
Snippets Groups Projects
Commit 6a51b7f0 authored by Jared Hancock's avatar Jared Hancock
Browse files

Tweak JSON attachment parsing for API

    * Don't require a content-type, so data:,this is content
      is perfectly allowable. Such content is assumed text/plain
    * Support the charset hint, so
      data:text/plain;charset=iso-8859-1,content here
      will be translated to UTF-8 if the php iconv() function exists.
      Otherwise, content is left intact and assumed by the database to by
      UTF-8 already
parent bb6a2bfe
No related branches found
No related tags found
No related merge requests found
......@@ -255,7 +255,7 @@ class ApiJsonDataParser extends JsonDataParser {
# PHP5: fopen("data://$data[5:]");
if (substr($data, 0, 5) != "data:") {
$info = array(
"data" => $data,
"data" => $data,
"type" => "text/plain",
"name" => key($info));
} else {
......@@ -264,11 +264,17 @@ class ApiJsonDataParser extends JsonDataParser {
list($type, $extra) = explode(";", $meta);
$info = array(
"data" => $contents,
"type" => $type,
"type" => ($type) ? $type : "text/plain",
"name" => key($info));
if (substr($extra, -6) == "base64")
$info["encoding"] = "base64";
# TODO: Handle 'charset' hint in $extra
# Handle 'charset' hint in $extra, such as
# data:text/plain;charset=iso-8859-1,Blah
# Convert to utf-8 since it's the encoding scheme
# for the database. Otherwise, assume utf-8
list($param,$charset) = explode('=', $extra);
if ($param == 'charset' && function_exists('iconv'))
$contents = iconv($charset, "UTF-8", $contents);
}
}
unset($value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment