Skip to content

fix(token-search): use TrimPrefix for sk- token normalization - #2928

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
RedwindA:fix/token-Search
Feb 12, 2026
Merged

fix(token-search): use TrimPrefix for sk- token normalization#2928
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
RedwindA:fix/token-Search

Conversation

@RedwindA

@RedwindA RedwindA commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

PR 类型

  • Bug 修复
  • 新功能
  • 文档更新
  • 其他

PR 是否包含破坏性更新?

PR 描述

修复后端 token 搜索逻辑中的字符串处理问题。

SearchUserTokens 中,原先使用 strings.Trim(token, "sk-") 对输入做处理,该方法会移除首尾所有属于 s / k /
- 的字符,可能错误修改 token 内容,导致搜索匹配失败。
本 PR 改为 strings.TrimPrefix(token, "sk-"),仅去除预期的 sk- 前缀,避免误删字符,恢复 token 搜索的正确性。

Summary by CodeRabbit

  • Bug Fixes
    • Changed token normalization to exclusively remove the "sk-" prefix from the beginning of tokens, replacing the previous approach of trimming any 's', 'k', or '-' characters from either end. Token searching and matching may behave differently for affected tokens.

@coderabbitai

coderabbitai Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Token normalization logic in model/token.go updated to precisely remove only the "sk-" prefix using TrimPrefix() instead of the previous approach that removed any of the characters 's', 'k', or '-' from both ends of the string.

Changes

Cohort / File(s) Summary
Token Normalization
model/token.go
Changed token prefix removal from TrimCharacters (removing any 's', 'k', '-' from ends) to TrimPrefix(token, "sk-") for precise leading prefix removal only.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A prefix so precise, no more ambiguous trim,
"sk-" comes right off, no mess to the brim,
One careful line change, makes tokens sing true,
CodeRabbit hops by, says "perfect for you!" 🎯

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing Trim with TrimPrefix for proper sk- prefix removal in token normalization logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Calcium-Ion
Calcium-Ion merged commit 61a5fa3 into QuantumNous:main Feb 12, 2026
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
fix(token-search): use TrimPrefix for sk- token normalization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants