[Filesystem] FIxed JS handling of encoding.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Tue, 28 Jul 2015 13:03:09 +0000 (15:03 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Tue, 28 Jul 2015 13:03:09 +0000 (15:03 +0200)
[Verification] Wearable UTC: 83/94.
               Mobile TCT: 289/289.

Change-Id: I6c6a6ca0b4add906f3ce9a7a6582c76865af693e
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/filesystem/js/file.js

index 1e031ab38c305899cb6159ad13d10c55cc898af5..d7e10389a3c77627e89bba931cbe44a23221263b 100755 (executable)
@@ -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),