Skip to content

Bug: CBand.decode strips leading zeros from wrapped flight numbers and can emit duplicate flight_number items #501

Description

@kevinelliott

Summary

CBand.decode builds the flight number as airline + Number(number), which coerces "0073"73 and drops leading zeros. Every other plugin (e.g. Label_H1_M_POS) uses a template literal to preserve them. In addition, when the wrapped inner plugin also emits its own flight_number item, both get pushed into formatted.items, so callers see two different flight numbers for the same message and raw.flight_number ends up disagreeing with the outer formatted item.

Location

lib/plugins/CBand.ts:56-65

ResultFormatter.flightNumber(
  decodeResult,
  cband.groups.airline + Number(cband.groups.number),   // <- coerces "0073" -> 73
);

decodeResult.raw = { ...decodeResult.raw, ...decoded.raw };            // inner overwrites raw.flight_number
decodeResult.formatted.items.push(...decoded.formatted.items);         // -> two FLIGHT items

Reproduction

new MessageDecoder().decode({
  label: 'H1',
  text: 'F37AQF0073M85AQF0073YSSY,KSFO,101621,-4.9985,-169.9820,35003,290',
});
// raw.flight_number === 'QF0073' (from inner Label_H1_M_POS)
// formatted.items contains BOTH
//   { code: 'FLIGHT', value: 'QF73' }   (from CBand, leading zero dropped)
//   { code: 'FLIGHT', value: 'QF0073' } (from inner plugin)

Impact

Silent-wrong-output — consumers matching flight numbers as strings will get QF73 (three-digit) mixed with QF0073 (four-digit) for the same aircraft, and any code that iterates formatted.items picks up the same field twice with conflicting values.

Suggested fix

Preserve the header string verbatim, and don't re-push the inner plugin's flight_number item:

ResultFormatter.flightNumber(
  decodeResult,
  `${cband.groups.airline}${cband.groups.number}`,
);

decodeResult.formatted.items.push(
  ...decoded.formatted.items.filter(it => it.code !== 'FLIGHT'),
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions