Skip to content
Browse files

Parse UTF-16 and UTF-8 BOM in all text uploads

  • Loading branch information...
1 parent db030df commit 9ff10f830158baa8fca5a938ede67d708dbdeb59 @vrana committed Mar 7, 2011
Showing with 10 additions and 2 deletions.
  1. +9 −1 adminer/include/functions.inc.php
  2. +1 −1 adminer/select.inc.php
View
10 adminer/include/functions.inc.php
@@ -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
View
2 adminer/select.inc.php
@@ -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);

0 comments on commit 9ff10f8

Please sign in to comment.
Something went wrong with that request. Please try again.