aboutsummaryrefslogtreecommitdiffstats
path: root/web_src
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2023-08-30 03:56:44 +0200
committerGitHub <noreply@github.com>2023-08-30 01:56:44 +0000
commit508de3a58d79009992df0e5f0cf1acedbac500bb (patch)
tree2969a3a969206d571b77a8960dc4cbedfe8efa75 /web_src
parent7bc80cb35012d5c3c6a5105ec8cd01b70de86ef7 (diff)
downloadgitea-508de3a58d79009992df0e5f0cf1acedbac500bb.tar.gz
gitea-508de3a58d79009992df0e5f0cf1acedbac500bb.zip
Fix Uint8Array comparisons and update vitest (#26805)
Compare those `Uint8Array` via conversion to Array which are properly comparable, so that we don't have to worry about whether `TextEncoder` and `UInt8Array` from the environment are compatible or not. --------- Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'web_src')
-rw-r--r--web_src/js/utils.test.js19
1 files changed, 12 insertions, 7 deletions
diff --git a/web_src/js/utils.test.js b/web_src/js/utils.test.js
index 812ef3bedf..6648b669c7 100644
--- a/web_src/js/utils.test.js
+++ b/web_src/js/utils.test.js
@@ -133,17 +133,22 @@ test('toAbsoluteUrl', () => {
expect(() => toAbsoluteUrl('path')).toThrowError('unsupported');
});
-const uint8array = (s) => new TextEncoder().encode(s);
test('encodeURLEncodedBase64, decodeURLEncodedBase64', () => {
+ // TextEncoder is Node.js API while Uint8Array is jsdom API and their outputs are not
+ // structurally comparable, so we convert to array to compare. The conversion can be
+ // removed once https://github.com/jsdom/jsdom/issues/2524 is resolved.
+ const encoder = new TextEncoder();
+ const uint8array = encoder.encode.bind(encoder);
+
expect(encodeURLEncodedBase64(uint8array('AA?'))).toEqual('QUE_'); // standard base64: "QUE/"
expect(encodeURLEncodedBase64(uint8array('AA~'))).toEqual('QUF-'); // standard base64: "QUF+"
- expect(decodeURLEncodedBase64('QUE/')).toEqual(uint8array('AA?'));
- expect(decodeURLEncodedBase64('QUF+')).toEqual(uint8array('AA~'));
- expect(decodeURLEncodedBase64('QUE_')).toEqual(uint8array('AA?'));
- expect(decodeURLEncodedBase64('QUF-')).toEqual(uint8array('AA~'));
+ expect(Array.from(decodeURLEncodedBase64('QUE/'))).toEqual(Array.from(uint8array('AA?')));
+ expect(Array.from(decodeURLEncodedBase64('QUF+'))).toEqual(Array.from(uint8array('AA~')));
+ expect(Array.from(decodeURLEncodedBase64('QUE_'))).toEqual(Array.from(uint8array('AA?')));
+ expect(Array.from(decodeURLEncodedBase64('QUF-'))).toEqual(Array.from(uint8array('AA~')));
expect(encodeURLEncodedBase64(uint8array('a'))).toEqual('YQ'); // standard base64: "YQ=="
- expect(decodeURLEncodedBase64('YQ')).toEqual(uint8array('a'));
- expect(decodeURLEncodedBase64('YQ==')).toEqual(uint8array('a'));
+ expect(Array.from(decodeURLEncodedBase64('YQ'))).toEqual(Array.from(uint8array('a')));
+ expect(Array.from(decodeURLEncodedBase64('YQ=='))).toEqual(Array.from(uint8array('a')));
});