mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-04 04:57:25 +00:00
chore: replace uint8-to-base64 with native btoa/atob (#38579)
Replace the single-use `uint8-to-base64` dependency with native `btoa`/`atob`. The implementation is exactly identical. --------- Signed-off-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -113,6 +113,12 @@ test('encodeURLEncodedBase64, decodeURLEncodedBase64', () => {
|
||||
expect(encodeURLEncodedBase64(uint8array('a'))).toEqual('YQ'); // standard base64: "YQ=="
|
||||
expect(new Uint8Array(decodeURLEncodedBase64('YQ'))).toEqual(uint8array('a'));
|
||||
expect(new Uint8Array(decodeURLEncodedBase64('YQ=='))).toEqual(uint8array('a'));
|
||||
|
||||
expect(encodeURLEncodedBase64(uint8array('AA'))).toEqual('QUE'); // standard base64: "QUE="
|
||||
expect(new Uint8Array(decodeURLEncodedBase64('QUE'))).toEqual(uint8array('AA'));
|
||||
|
||||
const allBytes = Uint8Array.from({length: 256}, (_, i) => i);
|
||||
expect(new Uint8Array(decodeURLEncodedBase64(encodeURLEncodedBase64(allBytes)))).toEqual(allBytes);
|
||||
});
|
||||
|
||||
test('formatBytes', () => {
|
||||
|
||||
+2
-5
@@ -1,4 +1,3 @@
|
||||
import {decode, encode} from 'uint8-to-base64';
|
||||
import type {IssuePageInfo, IssuePathInfo, RepoOwnerPathInfo} from './types.ts';
|
||||
import {toggleElemClass, toggleElem} from './utils/dom.ts';
|
||||
|
||||
@@ -158,7 +157,7 @@ export function toAbsoluteUrl(url: string): string {
|
||||
|
||||
/** Encode an Uint8Array into a URLEncoded base64 string. */
|
||||
export function encodeURLEncodedBase64(uint8Array: Uint8Array): string {
|
||||
return encode(uint8Array)
|
||||
return btoa(Array.from(uint8Array, (byte) => String.fromCharCode(byte)).join(''))
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/=/g, '');
|
||||
@@ -166,9 +165,7 @@ export function encodeURLEncodedBase64(uint8Array: Uint8Array): string {
|
||||
|
||||
/** Decode a URLEncoded base64 to an Uint8Array. */
|
||||
export function decodeURLEncodedBase64(base64url: string): Uint8Array {
|
||||
return decode(base64url
|
||||
.replace(/_/g, '/')
|
||||
.replace(/-/g, '+'));
|
||||
return Uint8Array.from(atob(base64url.replace(/_/g, '/').replace(/-/g, '+')), (ch) => ch.charCodeAt(0));
|
||||
}
|
||||
|
||||
const domParser = new DOMParser();
|
||||
|
||||
Reference in New Issue
Block a user