fix(login.sh): 变量紧跟全角字符导致 unbound variable(登录必败)+ API_KEY 未定义 - #18
Open
XPPilot wants to merge 1 commit into
Open
fix(login.sh): 变量紧跟全角字符导致 unbound variable(登录必败)+ API_KEY 未定义#18XPPilot wants to merge 1 commit into
XPPilot wants to merge 1 commit into
Conversation
问题一(导致登录必败):
第 114/117/138 行,$USER_ID / $ACTION 后紧跟全角括号「)」,
bash 5.x 在 UTF-8 locale 下将全角字符字节并入变量名,
在 set -u 下报 'USER_ID: unbound variable'。
任何新账号登录都在第 117 行中断,auth 文件无法落盘,
签到已执行但凭证丢失。
修复:统一改为 ${USER_ID} / ${ACTION} 大括号写法,共 3 处。
问题二(显示错误):
第 147 行引用 ${API_KEY},但该变量在脚本中从未定义,
永远 fallback 到硬编码值(作者本机 key,已进入开源仓库)。
用户修改过 config.json 的 api_key 后,此处必然 401,
重启后'当前账号数'恒显示 0。
修复:从 config.json 读取 api_key,保留原 fallback 兜底。
测试:
- bash -n 语法通过
- 最小复现:$VAR+全角字符 → unbound variable(与用户报错一致)
- 修复后对照测试 3 组全部通过
- 真实端到端:新账号 OAuth 登录 → auth 文件落盘 →
服务加载 2 个账号 → /v1/chat/completions 返回 200
- API_KEY 修复模拟测试:账号数显示 0 → 2(与实际一致)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
问题一:任何新账号登录必败(严重)
运行
./login.sh登录新账号,签到成功后脚本在 line 117 中断:后果:签到已执行但脚本死亡,auth 文件无法落盘,凭证丢失,用户只能反复重试。
根因:bash 5.x 在 UTF-8 locale 下,
$VAR后面紧跟全角字符时,全角字符的字节会被并入变量名。set -u下立即报 unbound variable:文件中共 3 处同类写法(line 114 / 117 / 138),全部修复为
${VAR}。问题二:API_KEY 引用了从未定义的变量(次要)
line 147 的
${API_KEY:-tistzach}:API_KEY在脚本中从未定义,永远 fallback 到硬编码值。该 fallback 值是作者本机的 key(已进入开源仓库),用户修改过 config.json 的api_key后此处必然 401,重启后「当前账号数」恒显示 0。修复:从 config.json 读取,保留原 fallback 兜底。
改动范围
仅
login.sh,+5/-3 行:$USER_ID→${USER_ID}$USER_ID→${USER_ID}$ACTION→${ACTION}API_KEY=$(python3 -c ...)从 config.json 读取不碰任何其他代码。(
python3与脚本既有 11 处依赖一致,无新增环境要求)测试
bash -n login.sh语法通过$VAR+全角字符 → unbound variable(与用户报错完全一致,含乱码字符)新账号(uid=...),新增 auth 文件→已保存(新增))→ 服务加载 →/v1/chat/completions返回 200附注
此前提交的 issue #17(token 截断)根因判断有误,已自行关闭并附勘误。本 PR 才是实测确认的真实问题。