Skip to content

Commit

Permalink
修复4399昵称中全角字符无法解码的问题 #13
Browse files Browse the repository at this point in the history
  • Loading branch information
Cnotech committed Sep 3, 2022
1 parent a617d8f commit 42b6e0e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"axios": "^0.27.2",
"cheerio": "^1.0.0-rc.10",
"chrome-remote-interface": "^0.31.2",
"decodeuricomponent": "^0.3.1",
"express": "^4.18.1",
"iconv": "^3.0.1",
"iconv-lite": "^0.6.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Iconv = require('iconv').Iconv
const decodeUriComponent = require('decodeuricomponent');

export default function (uri: string): string {
export function GBKEncodeUri(uri: string): string {
let i = new Iconv('UTF-8', 'GBK');
let from = i.convert(uri);
let rt = '';
Expand All @@ -16,3 +17,7 @@ export default function (uri: string): string {
}
return rt;
}

export function GBKDecodeUri(uri: string): string {
return decodeUriComponent(uri);
}
6 changes: 3 additions & 3 deletions packages/main/modules/com4399.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {GameInfo} from '../../class';
import {BrowserWindow} from 'electron';
import iconv from 'iconv-lite';
import cheerio from 'cheerio';
import GBKEncodeUri from "./GBKEncodeUri";
import {GBKEncodeUri,GBKDecodeUri} from "./GBKUri";

let cookie: string | null = null
let updateCookie: (cookie: string) => void
Expand Down Expand Up @@ -364,10 +364,10 @@ function getNickName(cookie: string): Result<string, string> {
if (m == null) {
return new Err("Error:Can't match nick name")
} else {
return new Ok(decodeURI(m[0].split(/[=;]/)[1]))
return new Ok(GBKDecodeUri(m[0].split(/[=;]/)[1]))
}
}
return new Ok(decodeURI(m[0].split(/[=;]/)[1]))
return new Ok(GBKDecodeUri(m[0].split(/[=;]/)[1]))
}

//4399pvz专题页面的补丁函数
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,13 @@ debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.4:
dependencies:
ms "2.1.2"

decodeuricomponent@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/decodeuricomponent/-/decodeuricomponent-0.3.1.tgz#4c3de9dd0fce86ca81da12ef0329e899d73e7c99"
integrity sha512-8PuirnWM7fdE54vRKoVT60RQlkFXgKsi7ToV4pdVbj9jc9qGSFt4P10Oi3UK+FPHZi+lhqRdPyG2QqhSfIhtQQ==
dependencies:
iconv-lite "^0.4.19"

decompress-response@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-3.3.0.tgz#80a4dd323748384bfa248083622aedec982adff3"
Expand Down Expand Up @@ -3016,7 +3023,7 @@ iconv-corefoundation@^1.1.7:
cli-truncate "^2.1.0"
node-addon-api "^1.6.3"

[email protected]:
[email protected], iconv-lite@^0.4.19:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
Expand Down

0 comments on commit 42b6e0e

Please sign in to comment.