Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Jan 17, 2026

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:

  • Dictionary was keyed by: "TBS LUCID_H7_WING" (first underscore → space)
  • Lookup used: "TBS_LUCID_H7_WING" (all underscores)
  • Result: Board not found in releases dictionary

Solution

  1. Added normalizeTargetName() function to convert hyphens to underscores for consistent matching
  2. Fixed parseFilename() and parseDevFilename() to replace ALL underscores/hyphens with spaces for display (using /g flag)
  3. Changed releases dictionary to be keyed by normalized raw_target instead of modified target
  4. Normalized all dictionary lookups to use consistent underscore format
  5. Added support for hyphen-based filenames as a workaround (e.g., TBS-LUCID-H7-WING)

Changes

  • tabs/firmware_flasher.js:
    • Add normalizeTargetName() function
    • Update parseFilename() to replace all underscores/hyphens
    • Update parseDevFilename() to replace all underscores/hyphens and accept hyphens in regex
    • Key releases dictionary by normalized targets
    • Normalize all lookups in board selection and FC auto-detect

Test Plan

  • Manual testing with INAV Configurator dev build
  • Verified board dropdown populates correctly
  • Verified no console errors
  • Confirmed fix handles both underscore and hyphen variants

Compatibility

  • Backwards compatible: Works with existing underscore-based filenames
  • Forward compatible: Also supports hyphen-based filenames as workaround

PR Type

Bug fix


Description

  • Add normalizeTargetName() function to convert hyphens to underscores

  • Fix board matching for multi-underscore target names like TBS_LUCID_H7_WING

  • Replace all underscores/hyphens with spaces in display names using /g flag

  • Normalize all dictionary lookups and board selection logic consistently


Diagram Walkthrough

flowchart LR
  A["Target Name<br/>TBS_LUCID_H7_WING"] --> B["normalizeTargetName()"]
  B --> C["Normalized<br/>TBS_LUCID_H7_WING"]
  C --> D["Dictionary Key<br/>Lookup"]
  D --> E["Board Found<br/>& Selected"]
  F["parseFilename()"] --> G["Replace All<br/>Underscores/Hyphens"]
  G --> H["Display Name<br/>TBS LUCID H7 WING"]
Loading

File Walkthrough

Relevant files
Bug fix
firmware_flasher.js
Normalize target names for consistent board matching         

tabs/firmware_flasher.js

  • Added normalizeTargetName() function to convert hyphens to underscores
    for consistent matching
  • Updated parseFilename() and parseDevFilename() to replace all
    underscores/hyphens with spaces using /g flag
  • Modified regex in parseDevFilename() to accept hyphens in target names
    ([A-Za-z0-9_-]+)
  • Changed all releases dictionary keys and lookups to use normalized
    raw_target instead of modified target
  • Normalized board selection and FC auto-detect logic to use consistent
    underscore format
+30/-14 

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).
@github-actions
Copy link

Branch Targeting Suggestion

You've targeted the master branch with this PR. Please consider if a version branch might be more appropriate:

  • maintenance-9.x - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.

  • maintenance-10.x - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x

If master is the correct target for this change, no action is needed.


This is an automated suggestion to help route contributions to the appropriate branch.

@sensei-hacker sensei-hacker changed the base branch from master to maintenance-9.x January 18, 2026 01:12
@sensei-hacker sensei-hacker marked this pull request as ready for review January 18, 2026 01:12
@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

@sensei-hacker sensei-hacker marked this pull request as draft January 18, 2026 01:14
Comment on lines +28 to +30
function normalizeTargetName(name) {
return name.replace(/-/g, '_');
}
Copy link
Contributor

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]

Suggested change
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant