Skip to content

Commit 8fffc44

Browse files
authored
Merge pull request #261 from cnblogs/fix-pat-input-validation
fix: PAT input validation
2 parents c601d77 + b05c96b commit 8fffc44

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/auth/auth-provider.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,22 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
8686

8787
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8888
async createSessionFromPat(scopes: string[]) {
89-
const opt = {
89+
const validateInput = (value: string) => {
90+
if (value.trim().length === 0)
91+
return '请输入个人访问令牌(PAT),如若没有,可以[创建](https://account.cnblogs.com/settings/tokens)'
92+
if (value.length > 500) return '无效的个人访问令牌(PAT)'
93+
}
94+
95+
const input = await window.showInputBox({
9096
title: '请输入您的个人访问令牌 (PAT)',
91-
prompt: '可通过 https://account.cnblos.com/tokens 获取',
97+
prompt: '可通过 [https://account.cnblogs.com/tokens](https://account.cnblogs.com/settings/tokens) 创建',
9298
password: true,
93-
validator: (value: string) => (value.length === 0 ? '个人访问令牌(PAT)不能为空' : ''),
94-
}
99+
validateInput,
100+
})
95101

96-
const pat = await window.showInputBox(opt)
97-
if ((pat ?? '').length === 0) throw new Error('个人访问令牌(PAT)不能为空')
102+
if (input == null) throw Error()
98103

99-
return authProvider.onAccessTokenGranted(pat ?? '', true)
104+
return authProvider.onAccessTokenGranted(input, true)
100105
}
101106

102107
createSessionFromBrowser(scopes: string[]) {

0 commit comments

Comments
 (0)