Skip to content

Bug: Label_2P_FM4 splits header on 'FM4' (no trailing space) unlike FM3/FM5, leaving a leading space in departure_icao #508

Description

@kevinelliott

Summary

Label_2P_FM4 splits its header on the token 'FM4', while the sibling plugins Label_2P_FM3 and Label_2P_FM5 split on 'FM3 ' and 'FM5 ' respectively (with a trailing space). Because FM4 lacks the trailing space and does not trim() the result, header[1] retains a leading space for the common FM4 <ICAO>,... header form, and that space is written straight into decodeResult.raw.departure_icao.

Location

lib/plugins/Label_2P_FM4.ts:24

const parts = message.text.split(',');

if (parts.length === 10) {
  const header = parts[0].split('FM4');   // FM3 uses 'FM3 ', FM5 uses 'FM5 '
  if (header.length < 2) {
    ...
  }
  if (header[0].length > 0) {
    ResultFormatter.unknown(decodeResult, header[0].substring(0, 4));
    ResultFormatter.flightNumber(decodeResult, header[0].substring(4));
  }
  ResultFormatter.departureAirport(decodeResult, header[1]);   // ← ' KIAD', not 'KIAD'
  ...
}

Compare with Label_2P_FM3.ts:25 (split('FM3 ')) and Label_2P_FM5.ts:24 (split('FM5 ')) — both use the space-terminated token, so header[1] starts cleanly on the ICAO.

Reproduction

const msg = {
  label: '2P',
  text: 'FM4 KIAD,OMAA,140256,1448, 39.43,- 75.62,23228,328,  43.5, 72500',
};
const result = new Label_2P_FM4().decode(msg);
// Actual:   result.raw.departure_icao === ' KIAD'
// Expected: result.raw.departure_icao === 'KIAD'

Impact

  • Downstream consumers keying off departure_icao won't match a leading-space value against normal 4-char ICAOs; the airport is effectively lost.
  • Any header without a trailing space (FM4KIAD,...) is still handled correctly by split('FM4 '), since the missing-header guard (header.length < 2) would then flag it as undecodable — the same behavior the FM3/FM5 siblings already have.

Suggested fix

Split on 'FM4 ' to match FM3/FM5:

const header = parts[0].split('FM4 ');

Add a test case with an FM4 <ICAO>,... input asserting raw.departure_icao === '<ICAO>' (no leading space).

Related

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