-
Notifications
You must be signed in to change notification settings - Fork 370
Fix firmware flasher board matching for multi-underscore targets #2522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: maintenance-9.x
Are you sure you want to change the base?
Fix firmware flasher board matching for multi-underscore targets #2522
Conversation
The firmware flasher was unable to match boards with multiple underscores in their names (like TBS_LUCID_H7_WING) because the old code only replaced the first underscore with a space, creating a mismatch between dictionary keys and lookup values. Changes: - Add normalizeTargetName() function to convert hyphens to underscores - Fix parseFilename() to replace ALL underscores/hyphens with spaces for display - Key releases dictionary by normalized raw_target instead of modified target - Normalize all lookups to use consistent underscore format - Support both underscore and hyphen filename variants This fixes board selection for targets like TBS_LUCID_H7_WING and enables support for hyphen-based filenames as a workaround (TBS-LUCID-H7-WING).
Branch Targeting SuggestionYou've targeted the
If This is an automated suggestion to help route contributions to the appropriate branch. |
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
| function normalizeTargetName(name) { | ||
| return name.replace(/-/g, '_'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: normalizeTargetName() assumes name is always a string, but new call sites pass values that can be 0, undefined, or non-strings; coerce/guard before using .replace() so the UI doesn’t crash on unexpected values. [Learned best practice, importance: 6]
| function normalizeTargetName(name) { | |
| return name.replace(/-/g, '_'); | |
| } | |
| function normalizeTargetName(name) { | |
| if (name == null) return ''; | |
| return String(name).replace(/-/g, '_'); | |
| } |
Eliminates 6 of 7 normalizeTargetName() calls by normalizing target names once at the data source (parseFilename/parseDevFilename functions) instead of repeatedly at consumption points. Changes: - Rename raw_target to target_id for semantic clarity - Add normalization in parseDevFilename() and parseFilename() - Remove redundant normalizeTargetName() calls throughout (6 eliminated) - Keep one necessary call for FC.CONFIG.target (external data source) Benefits: - Single normalization per filename parse (better performance) - Impossible to forget normalization (always available in result.target_id) - Clearer code intent and improved maintainability - Net reduction of 4 lines (17 insertions, 21 deletions)
- Simplify normalizeTargetName() comment to "Allow hyphens due to 9.0.0 patch" - Remove "Normalized: ..." comments since function name is self-explanatory - Keep "Display: ..." comments for clarity on user-facing strings
User description
Summary
Fixes firmware flasher board selection for targets with multiple underscores in their names (e.g.,
TBS_LUCID_H7_WING).Problem
The original code only replaced the first underscore with a space when creating display names, which caused a mismatch:
"TBS LUCID_H7_WING"(first underscore → space)"TBS_LUCID_H7_WING"(all underscores)Solution
normalizeTargetName()function to convert hyphens to underscores for consistent matchingparseFilename()andparseDevFilename()to replace ALL underscores/hyphens with spaces for display (using/gflag)raw_targetinstead of modifiedtargetTBS-LUCID-H7-WING)Changes
normalizeTargetName()functionparseFilename()to replace all underscores/hyphensparseDevFilename()to replace all underscores/hyphens and accept hyphens in regexTest Plan
Compatibility
PR Type
Bug fix
Description
Add
normalizeTargetName()function to convert hyphens to underscoresFix board matching for multi-underscore target names like
TBS_LUCID_H7_WINGReplace all underscores/hyphens with spaces in display names using
/gflagNormalize all dictionary lookups and board selection logic consistently
Diagram Walkthrough
File Walkthrough
firmware_flasher.js
Normalize target names for consistent board matchingtabs/firmware_flasher.js
normalizeTargetName()function to convert hyphens to underscoresfor consistent matching
parseFilename()andparseDevFilename()to replace allunderscores/hyphens with spaces using
/gflagparseDevFilename()to accept hyphens in target names(
[A-Za-z0-9_-]+)raw_targetinstead of modifiedtargetunderscore format