From 25017be8bfd6064c4d590bc9b82cc406b747fab7 Mon Sep 17 00:00:00 2001
From: Pawel Andruszkiewicz
Date: Tue, 28 Jul 2015 15:03:09 +0200
Subject: [PATCH] [Filesystem] FIxed JS handling of encoding.
[Verification] Wearable UTC: 83/94.
Mobile TCT: 289/289.
Change-Id: I6c6a6ca0b4add906f3ce9a7a6582c76865af693e
Signed-off-by: Pawel Andruszkiewicz
---
src/filesystem/js/file.js | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
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),
--
2.34.1