From: Pawel Andruszkiewicz Date: Tue, 28 Jul 2015 13:03:09 +0000 (+0200) Subject: [Filesystem] FIxed JS handling of encoding. X-Git-Tag: submit/tizen_tv/20150803.021740^2^2~16^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=25017be8bfd6064c4d590bc9b82cc406b747fab7;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] FIxed JS handling of encoding. [Verification] Wearable UTC: 83/94. Mobile TCT: 289/289. Change-Id: I6c6a6ca0b4add906f3ce9a7a6582c76865af693e Signed-off-by: Pawel Andruszkiewicz --- diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js index 1e031ab3..d7e10389 100755 --- a/src/filesystem/js/file.js +++ b/src/filesystem/js/file.js @@ -218,16 +218,19 @@ File.prototype.listFiles = function(onsuccess, onerror, filter) { var Encoding = { 'utf-8': 'utf-8', - 'iso-8859-1': 'iso-8859-1' + 'iso-8859-1': 'iso-8859-1', + 'sjis': 'sjis', // backward compatibility + 'null': 'utf-8', + 'undefined': 'utf-8' }; function _checkEncoding(encoding) { - if (encoding) { - var _validEncoding = Object.keys(Encoding); - if (_validEncoding.indexOf((encoding.toLowerCase())) < 0) { - throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, - 'Argument "encoding" has invalid value'); - } + encoding = String(encoding).toLowerCase(); + if (undefined === Encoding[encoding]) { + throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, + 'Argument "encoding" has invalid value: ' + encoding); + } else { + return Encoding[encoding]; } } @@ -262,7 +265,7 @@ File.prototype.openStream = function(mode, onsuccess, onerror, encoding) { return; } - _checkEncoding(args.encoding); + args.encoding = _checkEncoding(args.encoding); var _realPath = commonFS_.toRealPath(this.fullPath); var _result = native_.callSync('File_statSync', {location: _realPath}); @@ -302,7 +305,7 @@ File.prototype.readAsText = function(onsuccess, onerror, encoding) { return; } - _checkEncoding(args.encoding); + args.encoding = _checkEncoding(args.encoding); var data = { location: commonFS_.toRealPath(this.fullPath),