fix: base64 encoding on vmess/shadowsocks inbounds (#2736)

This commit is contained in:
Shishkevich D. 2025-03-08 12:33:34 +07:00 committed by GitHub
parent 6658f648e6
commit 751f564c4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -515,17 +515,22 @@ class ClipboardManager {
class Base64 {
static encode(content = "", safe = false) {
if (safe) {
return window.btoa(content)
return Base64.encode(content)
.replace(/\+/g, '-')
.replace(/=/g, '')
.replace(/\//g, '_')
}
return window.btoa(content)
return window.btoa(
String.fromCharCode(...new TextEncoder().encode(content))
)
}
static decode(content = "") {
return window.atob(content)
return new TextDecoder()
.decode(
Uint8Array.from(window.atob(content), c => c.charCodeAt(0))
)
}
}