From f3311bcddf4a68fd3c3c14d23585e91a0c56feab Mon Sep 17 00:00:00 2001
From: Pawel Wasowski
Date: Tue, 11 Apr 2017 15:41:15 +0200
Subject: [PATCH] [Filesystem] Substitute codePointAt with getCodePoint
getCodePoint() provides the functionality of String.prototype.codePointAt(),
which is unsupported on some devices.
[Verification] TCT Filesystem tests: the pass rate did not change.
Signed-off-by: Pawel Wasowski
Change-Id: Id1d1df587a41494934dc01f1c88e417982f9b64f
---
src/filesystem/js/base64.js | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/filesystem/js/base64.js b/src/filesystem/js/base64.js
index d2868f3e..edd45133 100755
--- a/src/filesystem/js/base64.js
+++ b/src/filesystem/js/base64.js
@@ -83,13 +83,30 @@ var Base64 = {
return output;
},
+ getCodePoint: function(string, position) {
+ var highWord = string.charCodeAt(position);
+
+ if ((highWord & 0xFC00) === 0xD800) {
+ if (position + 1 >= string.length) {
+ return undefined; //the string is corrupted
+ }
+
+ var lowWord = string.charCodeAt(position + 1);
+ if ((lowWord & 0xFC00) === 0xDC00) {
+ return ((highWord & 0x03FF) << 10) | (lowWord & 0x03FF) + 0x10000;
+ } else {
+ return undefined; //the string is corrupted
+ }
+ }
+ return highWord;
+ },
_utf8_encode: function(str) {
str = str.replace(/\r\n/g, '\n');
var utfarray = [];
//TODO: use for( var c of str ) in future versions
for (var offset = 0; offset < str.length; offset++) {
- var code = str.codePointAt(offset);
+ var code = this.getCodePoint(str, offset);
if (code <= 0x7F) {
utfarray.push(code);
--
2.34.1