Skip to content

Commit e5f300d

Browse files
authored
UI: Bugfix. Move to a different TextEncoder/Decoder (#4613)
1. The previously used TextEncoder/Decoder (used as a polyfill for browsers that don't have a native version) didn't expose an encoder via CommonJS. Use a different polyfill that exposes both a decoder and an encoder. 2. The feature detection itself was flawed. This does a less error prone detection that ensures native encoding/decoding where available and polyfilled encoding/decoding where not available.
1 parent f916962 commit e5f300d

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

ui-v2/app/utils/atob.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import TextEncoderLite from 'npm:text-encoder-lite';
1+
import TextEncoding from 'npm:text-encoding';
22
import base64js from 'npm:base64-js';
33
export default function(str, encoding = 'utf-8') {
4-
// str = String(str).trim();
5-
//decode
4+
// decode
65
const bytes = base64js.toByteArray(str);
7-
return new (TextDecoder || TextEncoderLite)(encoding).decode(bytes);
6+
return new ('TextDecoder' in window ? TextDecoder : TextEncoding.TextDecoder)(encoding).decode(
7+
bytes
8+
);
89
}

ui-v2/app/utils/btoa.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import TextEncoderLite from 'npm:text-encoder-lite';
1+
import TextEncoding from 'npm:text-encoding';
22
import base64js from 'npm:base64-js';
33
export default function(str, encoding = 'utf-8') {
44
// encode
5-
const bytes = new (TextEncoder || TextEncoderLite)(encoding).encode(str);
5+
const bytes = new ('TextEncoder' in window ? TextEncoder : TextEncoding.TextEncoder)(encoding).encode(str);
66
return base64js.fromByteArray(bytes);
77
}

ui-v2/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"loader.js": "^4.2.3",
8787
"prettier": "^1.10.2",
8888
"svgo": "^1.0.5",
89-
"text-encoder-lite": "^1.0.1"
89+
"text-encoding": "^0.6.4"
9090
},
9191
"engines": {
9292
"node": "^4.5 || 6.* || >= 7.*"

ui-v2/yarn.lock

-4
Original file line numberDiff line numberDiff line change
@@ -8933,10 +8933,6 @@ testem@^2.0.0:
89338933
tap-parser "^5.1.0"
89348934
xmldom "^0.1.19"
89358935

8936-
text-encoder-lite@^1.0.1:
8937-
version "1.0.1"
8938-
resolved "https://registry.yarnpkg.com/text-encoder-lite/-/text-encoder-lite-1.0.1.tgz#121c5ee74dfeb307037770ec75748c6824ac0518"
8939-
89408936
[email protected], text-encoding@^0.6.4:
89418937
version "0.6.4"
89428938
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"

0 commit comments

Comments
 (0)