fix: inconsistent format issue when checking if the plugin is installed#7493
Open
Waterwzy wants to merge 3 commits intoAstrBotDevs:masterfrom
Open
fix: inconsistent format issue when checking if the plugin is installed#7493Waterwzy wants to merge 3 commits intoAstrBotDevs:masterfrom
Waterwzy wants to merge 3 commits intoAstrBotDevs:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The normalization for plugin names only replaces
_with-; if you want true consistency, consider a shared helper (e.g.,normalizeName(name)) that also handles casing and both_/-directions so the logic is not duplicated inline and is easier to maintain. - The inline comments on the
replacecalls explain the intent but are embedded at the end of long lines; consider extracting the logic into a clearly named function or adding a brief comment above the block to keep line length shorter and semantics clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The normalization for plugin names only replaces `_` with `-`; if you want true consistency, consider a shared helper (e.g., `normalizeName(name)`) that also handles casing and both `_`/`-` directions so the logic is not duplicated inline and is easier to maintain.
- The inline comments on the `replace` calls explain the intent but are embedded at the end of long lines; consider extracting the logic into a clearly named function or adding a brief comment above the block to keep line length shorter and semantics clearer.
## Individual Comments
### Comment 1
<location path="dashboard/src/views/extension/useExtensionPage.js" line_range="1291" />
<code_context>
const data = Array.isArray(extension_data?.data) ? extension_data.data : [];
const installedRepos = new Set(data.map((ext) => ext.repo?.toLowerCase()));
- const installedNames = new Set(data.map((ext) => ext.name));
+ const installedNames = new Set(data.map((ext) => ext.name.replace(/_/g, '-')));//统一格式,以防下面的匹配不生效
const installedByRepo = new Map(
data
</code_context>
<issue_to_address>
**issue (bug_risk):** Defensive check for `ext.name` before calling `replace` to avoid runtime errors.
If any `data` entry has a missing or non-string `name`, `ext.name.replace` will throw. Consider a small helper, e.g. `const normalizeName = (name) => String(name || '').replace(/_/g, '-');` and use `normalizeName(ext.name)` here.
</issue_to_address>
### Comment 2
<location path="dashboard/src/views/extension/useExtensionPage.js" line_range="1321" />
<code_context>
plugin.installed =
installedRepos.has(plugin.repo?.toLowerCase()) ||
- installedNames.has(plugin.name);
+ installedNames.has(plugin.name.replace(/_/g, '-'));//统一格式,防止匹配失败
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Also guard `plugin.name` when calling `replace` to prevent potential crashes.
If `plugin.name` is ever null/undefined or not a string, calling `.replace` will throw. Consider guarding it or using a small helper like `normalizeName(plugin.name)` to safely normalize and reuse the logic.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the extension installation check to normalize plugin names by replacing underscores with hyphens. The review feedback suggests further improving the robustness of this matching by incorporating case-insensitivity and string normalization via the normalizeStr utility, while also ensuring consistency across other name-based lookups in the file.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Soulter
approved these changes
Apr 12, 2026
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.
Fix #7491
Modifications / 改动点
dashboard/src/views/extension/useExtensionPage.js-和_的一致性Screenshots or Test Results / 运行截图或测试结果
当本地repo与插件市场repo不一致时:
说明astrbot正确识别匹配了插件名称
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Bug Fixes: