Skip to content

Commit

Permalink
Parse UTF-16 and UTF-8 BOM in all text uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed Mar 7, 2011
1 parent db030df commit 9ff10f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion adminer/include/functions.inc.php
Expand Up @@ -489,10 +489,18 @@ function get_file($key, $decompress = false) {
if (!$file || $file["error"]) {
return $file["error"];
}
return file_get_contents($decompress && ereg('\\.gz$', $file["name"]) ? "compress.zlib://$file[tmp_name]"
$return = file_get_contents($decompress && ereg('\\.gz$', $file["name"]) ? "compress.zlib://$file[tmp_name]"
: ($decompress && ereg('\\.bz2$', $file["name"]) ? "compress.bzip2://$file[tmp_name]"
: $file["tmp_name"]
)); //! may not be reachable because of open_basedir
if ($decompress) {
if (function_exists("iconv") && ereg("^\xFE\xFF|^\xFF\xFE", $return, $regs)) {
$return = iconv("utf-16", "utf-8", $return);
} else { // not ternary operator to save memory
$return = ereg_replace("^\xEF\xBB\xBF", "", $return); // UTF-8 BOM
}
}
return $return;
}

/** Determine upload error
Expand Down
2 changes: 1 addition & 1 deletion adminer/select.inc.php
Expand Up @@ -141,7 +141,7 @@
queries_redirect(remove_from_uri(), lang('%d item(s) have been affected.', $affected), $result);
}
} elseif (is_string($file = get_file("csv_file", true))) {
$file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
//! character set
$result = true;
$cols = array_keys($fields);
preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches);
Expand Down

0 comments on commit 9ff10f8

Please sign in to comment.