diff --git a/backend/package.json b/backend/package.json index 6d4fdbd..8dcf1b8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.233", + "version": "2.14.235", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index 3859659..b511032 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -1,6 +1,12 @@ import YAML from '@/utils/yaml'; import download from '@/utils/download'; -import { isIPv4, isIPv6, isValidPortNumber, isNotBlank } from '@/utils'; +import { + isIPv4, + isIPv6, + isValidPortNumber, + isNotBlank, + utf8ArrayToStr, +} from '@/utils'; import PROXY_PROCESSORS, { ApplyProcessor } from './processors'; import PROXY_PREPROCESSORS from './preprocessors'; import PROXY_PRODUCERS from './producers'; @@ -370,6 +376,18 @@ function lastParse(proxy) { } } } + if (typeof proxy.name !== 'string') { + try { + if (proxy.name?.data) { + proxy.name = Buffer.from(proxy.name.data).toString('utf8'); + } else { + proxy.name = utf8ArrayToStr(proxy.name); + } + } catch (e) { + $.error(`proxy.name decode failed\nReason: ${e}`); + proxy.name = `${proxy.type} ${proxy.server}:${proxy.port}`; + } + } return proxy; } diff --git a/backend/src/utils/index.js b/backend/src/utils/index.js index 0502b92..d49ae7b 100644 --- a/backend/src/utils/index.js +++ b/backend/src/utils/index.js @@ -35,6 +35,53 @@ function getIfPresent(obj, defaultValue) { return isPresent(obj) ? obj : defaultValue; } +const utf8ArrayToStr = + typeof TextDecoder !== 'undefined' + ? (v) => new TextDecoder().decode(new Uint8Array(v)) + : (function () { + var charCache = new Array(128); // Preallocate the cache for the common single byte chars + var charFromCodePt = String.fromCodePoint || String.fromCharCode; + var result = []; + + return function (array) { + var codePt, byte1; + var buffLen = array.length; + + result.length = 0; + + for (var i = 0; i < buffLen; ) { + byte1 = array[i++]; + + if (byte1 <= 0x7f) { + codePt = byte1; + } else if (byte1 <= 0xdf) { + codePt = ((byte1 & 0x1f) << 6) | (array[i++] & 0x3f); + } else if (byte1 <= 0xef) { + codePt = + ((byte1 & 0x0f) << 12) | + ((array[i++] & 0x3f) << 6) | + (array[i++] & 0x3f); + } else if (String.fromCodePoint) { + codePt = + ((byte1 & 0x07) << 18) | + ((array[i++] & 0x3f) << 12) | + ((array[i++] & 0x3f) << 6) | + (array[i++] & 0x3f); + } else { + codePt = 63; // Cannot convert four byte code points, so use "?" instead + i += 3; + } + + result.push( + charCache[codePt] || + (charCache[codePt] = charFromCodePt(codePt)), + ); + } + + return result.join(''); + }; + })(); + export { isIPv4, isIPv6, @@ -43,4 +90,5 @@ export { getIfNotBlank, isPresent, getIfPresent, + utf8ArrayToStr, };