mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-30 19:08:37 +00:00 
			
		
		
		
	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>
This commit is contained in:
		| @@ -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'))); | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user