Skip to content

Commit

Permalink
fix: garbled text in vmess and shadowsocks
Browse files Browse the repository at this point in the history
  • Loading branch information
7Sageer committed Sep 23, 2024
1 parent cf59df0 commit f43f803
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Sublink Worker 是一个可部署在 Cloudflare Worker 上,小而美的订阅

## 最近更新

- 2024-09-20 在公共站点启用新域名(https://sublink-worker.sageer.me)
- 2024-09-23
- 修复了VMess和Shadowsocks url中文可能出现乱码的问题

[查看更新日志](/doc/update-log.md)

Expand Down
6 changes: 5 additions & 1 deletion doc/update-log.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 更新日志

## 2024 09-20
## 2024-09-23

- 修复了VMess和Shadowsocks url中文可能出现乱码的问题

## 2024-09-20

- 在公共站点启用新域名(https://sublink-worker.sageer.me)

Expand Down
10 changes: 6 additions & 4 deletions src/ProxyParsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ export class ProxyParser {
let parts = url.replace('ss://', '').split('#');
let mainPart = parts[0];
let tag = parts[1];
if (tag.includes('%')) {
tag = decodeURIComponent(tag);
}

let [base64, serverPart] = mainPart.split('@');
let decodedParts = atob(base64).split(':');
let decodedParts = decodeBase64(base64).split(':');
let method = decodedParts[0];
let password = decodedParts.slice(1).join(':');

Expand Down Expand Up @@ -56,7 +59,7 @@ export class ProxyParser {
class VmessParser {
parse(url) {
let base64 = url.replace('vmess://', '')
let vmessConfig = JSON.parse(atob(base64))
let vmessConfig = JSON.parse(decodeBase64(base64))
let tls = { "enabled": false }
let transport = {}
if (vmessConfig.net === 'ws') {
Expand Down Expand Up @@ -172,8 +175,7 @@ export class ProxyParser {
}

class TuicParser {
//tuic://9a92c965-2c57-4040-8c83-330374e34424:[email protected]:10876?sni=wawo33.qhr.icu&alpn=h3&congestion_control=bbr#HK-singbox_tuic


parse(url) {
const { addressPart, params, name } = parseUrlParams(url);
const [userinfo, serverInfo] = addressPart.split('@');
Expand Down
3 changes: 1 addition & 2 deletions src/SingboxConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export class ConfigBuilder extends BaseConfigBuilder {
}

const proxyList = this.config.outbounds.filter(outbound => outbound?.server != undefined).map(outbound => outbound.tag);

console.log(proxyList);

this.config.outbounds.unshift({
type: "urltest",
tag: "⚡ 自动选择",
Expand Down
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const PATH_LENGTH = 7;

export function decodeBase64(str) {
return atob(str);
const binString = atob(str);
const bytes = Uint8Array.from(binString, (m) => m.codePointAt(0));
return new TextDecoder().decode(bytes);
}
export function encodeBase64(str) {
return btoa(str);
Expand Down

0 comments on commit f43f803

Please sign in to comment.