fix(awards): apply the reference Prefix where it can actually help

Prefix exists so a field holding a bare value counts for an award whose codes
carry a letter: a French operator writes "74" in STATE, DDFM's codes are "D74".
Def's own doc says exactly that. But searchOne applied the prefix AFTER looking
the token up in the reference list — after the step that had just failed — so
the bare form matched nothing and the prefix decorated an empty result. The only
way through was a regex, in a mode where the operator had chosen "code" and
explicitly not "pattern".

The token lookup now tries the prefixed form when the bare one is not a known
reference. The list stays the authority: an unknown number still matches
nothing, so the prefix completes references rather than inventing them.

Second bug in the same pass: the blanket prefix also hit codes that came
straight OUT of the list, so a field already holding "D74" produced "DD74" as
soon as a prefix was configured — for both the token lookup and the
description matcher. Branches that yield whole codes are now excluded from it;
the ones that yield a raw capture (regex, whole-field split) still get it.
This commit is contained in:
2026-08-09 09:43:27 +02:00
parent 4352b9aec5
commit 79427ccd18
3 changed files with 103 additions and 1 deletions
+2
View File
@@ -6,6 +6,7 @@
"Worked before: an operator's portable callsigns now count as the same station. Typing RK3DWA finds the RK3DWA/3, /P and /MM contacts too, and the other way round — before, the history only appeared if you typed the exact form. Can be turned off in Settings → General; contest dupe checking is unaffected and stays exact.", "Worked before: an operator's portable callsigns now count as the same station. Typing RK3DWA finds the RK3DWA/3, /P and /MM contacts too, and the other way round — before, the history only appeared if you typed the exact form. Can be turned off in Settings → General; contest dupe checking is unaffected and stays exact.",
"QSO editor: the OpsLog card now appears with the other confirmations. It has its own Sent / Received row in the QSL Info table, next to QSL, LoTW, eQSL and the rest, and the \"QSL received\" tick moved there from Contact's details — with its PSE QSL / TNX indicator, which is unchanged. Sent stays read-only: OpsLog stamps it when the card actually goes out.", "QSO editor: the OpsLog card now appears with the other confirmations. It has its own Sent / Received row in the QSL Info table, next to QSL, LoTW, eQSL and the rest, and the \"QSL received\" tick moved there from Contact's details — with its PSE QSL / TNX indicator, which is unchanged. Sent stays read-only: OpsLog stamps it when the card actually goes out.",
"QSL card: the {qso.pse_tnx} stamp now prints \"TNX QSL\" instead of just \"TNX\", to read as the counterpart of \"PSE QSL\".", "QSL card: the {qso.pse_tnx} stamp now prints \"TNX QSL\" instead of just \"TNX\", to read as the counterpart of \"PSE QSL\".",
"Awards: the Prefix now completes a reference the operator typed without it. A station that puts just \"74\" in State counts for DDFM (codes D01…D95) with match-by \"code\" and Prefix \"D\" — before, that found nothing and the only way through was to write a regex, in a mode where you had chosen \"code\" and not \"pattern\". The prefix was applied after the reference lookup, that is, after the step that had already failed. A field that already holds the whole code is no longer prefixed twice either (\"D74\" used to become \"DD74\" as soon as a prefix was set).",
"UDP: WSJT-X traffic arriving through a relay is read again. A forwarder such as W&P prepends the origin as text — \"127.0.0.1:2237|\" — in front of the packet it re-broadcasts, which pushed the WSJT-X signature 15 bytes in and made every datagram fail. That header is now skipped, so MSHV / WSJT-X / JTDX behind a relay work on the ordinary \"WSJT-X / JTDX / MSHV\" service: no new setting, nothing to reconfigure.", "UDP: WSJT-X traffic arriving through a relay is read again. A forwarder such as W&P prepends the origin as text — \"127.0.0.1:2237|\" — in front of the packet it re-broadcasts, which pushed the WSJT-X signature 15 bytes in and made every datagram fail. That header is now skipped, so MSHV / WSJT-X / JTDX behind a relay work on the ordinary \"WSJT-X / JTDX / MSHV\" service: no new setting, nothing to reconfigure.",
"UDP: an unreadable packet now says who sent it and what it contained — the sender's address, the size, a text preview and a hex dump — instead of just a magic number. And it stops after five: a port receiving the wrong traffic was writing that line a hundred times a second, filling the log and burying everything else. A closing line points at the two things to check, the sender and the service type.", "UDP: an unreadable packet now says who sent it and what it contained — the sender's address, the size, a text preview and a hex dump — instead of just a magic number. And it stops after five: a port receiving the wrong traffic was writing that line a hundred times a second, filling the log and burying everything else. A closing line points at the two things to check, the sender and the service type.",
"Awards: the QRZ.com and Custom confirmation sources actually work now. Both were offered in the award editor but neither was implemented, so ticking one marked no QSO as confirmed — silently. QRZ.com reads the download status (them confirming back, not our upload). Custom reads any QSO field or ADIF tag you name, with an optional list of values that count: point it at APP_OPSLOG_QSL_RCVD for a card received through OpsLog, or at a tag stamped by a club list you imported. Leave the value empty and any non-empty content confirms. A Custom source naming no field confirms nothing.", "Awards: the QRZ.com and Custom confirmation sources actually work now. Both were offered in the award editor but neither was implemented, so ticking one marked no QSO as confirmed — silently. QRZ.com reads the download status (them confirming back, not our upload). Custom reads any QSO field or ADIF tag you name, with an optional list of values that count: point it at APP_OPSLOG_QSL_RCVD for a card received through OpsLog, or at a tag stamped by a club list you imported. Leave the value empty and any non-empty content confirms. A Custom source naming no field confirms nothing.",
@@ -15,6 +16,7 @@
"Déjà contacté : les indicatifs portables d'un opérateur comptent désormais comme la même station. Taper RK3DWA retrouve aussi les QSO en RK3DWA/3, /P et /MM, et inversement — avant, l'historique n'apparaissait que si tu tapais la forme exacte. Désactivable dans Réglages → Général ; le contrôle de doublon en concours n'est pas touché et reste strict.", "Déjà contacté : les indicatifs portables d'un opérateur comptent désormais comme la même station. Taper RK3DWA retrouve aussi les QSO en RK3DWA/3, /P et /MM, et inversement — avant, l'historique n'apparaissait que si tu tapais la forme exacte. Désactivable dans Réglages → Général ; le contrôle de doublon en concours n'est pas touché et reste strict.",
"Éditeur de QSO : la carte OpsLog rejoint les autres confirmations. Elle a sa propre ligne Envoyée / Reçue dans le tableau de l'onglet QSL Info, à côté de QSL, LoTW, eQSL et les autres, et la case « QSL reçue » y a été déplacée depuis Détails du contact — avec son indicateur PSE QSL / TNX, inchangé. « Envoyée » reste en lecture seule : OpsLog l'inscrit quand la carte part réellement.", "Éditeur de QSO : la carte OpsLog rejoint les autres confirmations. Elle a sa propre ligne Envoyée / Reçue dans le tableau de l'onglet QSL Info, à côté de QSL, LoTW, eQSL et les autres, et la case « QSL reçue » y a été déplacée depuis Détails du contact — avec son indicateur PSE QSL / TNX, inchangé. « Envoyée » reste en lecture seule : OpsLog l'inscrit quand la carte part réellement.",
"Carte QSL : le tampon {qso.pse_tnx} imprime désormais « TNX QSL » et non plus « TNX » seul, pour répondre à « PSE QSL ».", "Carte QSL : le tampon {qso.pse_tnx} imprime désormais « TNX QSL » et non plus « TNX » seul, pour répondre à « PSE QSL ».",
"Diplômes : le Préfixe complète désormais une référence saisie sans lui. Une station qui met simplement « 74 » dans State compte pour le DDFM (codes D01…D95) avec correspondance « code » et Préfixe « D » — avant, cela ne trouvait rien et le seul recours était d'écrire une regex, dans un mode où tu avais justement choisi « code » et pas « pattern ». Le préfixe était appliqué après la recherche de la référence, c'est-à-dire après l'étape qui venait d'échouer. Un champ contenant déjà le code complet n'est plus préfixé deux fois non plus (« D74 » devenait « DD74 » dès qu'un préfixe était réglé).",
"UDP : le trafic WSJT-X qui arrive via un relais est de nouveau lu. Un réexpéditeur comme W&P place l'origine en texte — « 127.0.0.1:2237| » — devant le paquet qu'il rediffuse, ce qui décalait la signature WSJT-X de 15 octets et faisait échouer chaque datagramme. Cet en-tête est désormais ignoré : MSHV / WSJT-X / JTDX derrière un relais fonctionnent avec le service « WSJT-X / JTDX / MSHV » habituel, sans nouveau réglage ni reconfiguration.", "UDP : le trafic WSJT-X qui arrive via un relais est de nouveau lu. Un réexpéditeur comme W&P place l'origine en texte — « 127.0.0.1:2237| » — devant le paquet qu'il rediffuse, ce qui décalait la signature WSJT-X de 15 octets et faisait échouer chaque datagramme. Cet en-tête est désormais ignoré : MSHV / WSJT-X / JTDX derrière un relais fonctionnent avec le service « WSJT-X / JTDX / MSHV » habituel, sans nouveau réglage ni reconfiguration.",
"UDP : un paquet illisible indique désormais qui l'a envoyé et ce qu'il contenait — adresse de l'émetteur, taille, aperçu en texte et vidage hexadécimal — au lieu d'un simple nombre magique. Et il s'arrête après cinq : un port recevant le mauvais trafic écrivait cette ligne cent fois par seconde, saturant le journal et enterrant tout le reste. Une ligne finale rappelle les deux choses à vérifier, l'émetteur et le type de service.", "UDP : un paquet illisible indique désormais qui l'a envoyé et ce qu'il contenait — adresse de l'émetteur, taille, aperçu en texte et vidage hexadécimal — au lieu d'un simple nombre magique. Et il s'arrête après cinq : un port recevant le mauvais trafic écrivait cette ligne cent fois par seconde, saturant le journal et enterrant tout le reste. Une ligne finale rappelle les deux choses à vérifier, l'émetteur et le type de service.",
"Diplômes : les sources de confirmation QRZ.com et Custom fonctionnent enfin. Les deux étaient proposées dans l'éditeur de diplômes sans être implémentées : cocher l'une ou l'autre ne confirmait aucun QSO, en silence. QRZ.com lit le statut de téléchargement (leur confirmation en retour, pas notre envoi). Custom lit n'importe quel champ de QSO ou balise ADIF que tu désignes, avec une liste facultative de valeurs qui comptent : pointe-la sur APP_OPSLOG_QSL_RCVD pour une carte reçue via OpsLog, ou sur une balise inscrite à l'import d'une liste de club. Laisse la valeur vide et tout contenu non vide confirme. Une source Custom sans champ ne confirme rien.", "Diplômes : les sources de confirmation QRZ.com et Custom fonctionnent enfin. Les deux étaient proposées dans l'éditeur de diplômes sans être implémentées : cocher l'une ou l'autre ne confirmait aucun QSO, en silence. QRZ.com lit le statut de téléchargement (leur confirmation en retour, pas notre envoi). Custom lit n'importe quel champ de QSO ou balise ADIF que tu désignes, avec une liste facultative de valeurs qui comptent : pointe-la sur APP_OPSLOG_QSL_RCVD pour une carte reçue via OpsLog, ou sur une balise inscrite à l'import d'une liste de club. Laisse la valeur vide et tout contenu non vide confirme. Une source Custom sans champ ne confirme rien.",
+20 -1
View File
@@ -793,6 +793,10 @@ func searchOne(field, matchBy string, re *regexp.Regexp, exact bool, leading, tr
byDesc := predefined && strings.EqualFold(strings.TrimSpace(matchBy), "description") byDesc := predefined && strings.EqualFold(strings.TrimSpace(matchBy), "description")
var found []string var found []string
// codesAreFinal: this branch produced references straight from the award's
// LIST, so they are already whole codes. The blanket prefix at the end must
// leave them alone — prefixing a code that is already "D74" yields "DD74".
codesAreFinal := false
switch { switch {
case re != nil: case re != nil:
// Award-level regex: capture group 1 (or whole match) for each hit. // Award-level regex: capture group 1 (or whole match) for each hit.
@@ -801,6 +805,7 @@ func searchOne(field, matchBy string, re *regexp.Regexp, exact bool, leading, tr
// Match references by their DESCRIPTION/name appearing in the field // Match references by their DESCRIPTION/name appearing in the field
// (e.g. WAJA finds the prefecture name inside the QTH). ExactMatch means // (e.g. WAJA finds the prefecture name inside the QTH). ExactMatch means
// the field equals the name; otherwise the name is a substring of it. // the field equals the name; otherwise the name is a substring of it.
codesAreFinal = true
up := strings.ToUpper(raw) up := strings.ToUpper(raw)
for _, nc := range rl.names { for _, nc := range rl.names {
if exact { if exact {
@@ -823,9 +828,23 @@ func searchOne(field, matchBy string, re *regexp.Regexp, exact bool, leading, tr
// "Search reference inside the field": look up each token of the field in // "Search reference inside the field": look up each token of the field in
// the list — O(tokens), not O(all references) — plus test the few // the list — O(tokens), not O(all references) — plus test the few
// references that declare a regex. // references that declare a regex.
codesAreFinal = true
for _, tok := range tokenize(raw) { for _, tok := range tokenize(raw) {
if _, ok := rl.byCode[tok]; ok { if _, ok := rl.byCode[tok]; ok {
found = append(found, tok) found = append(found, tok)
continue
}
// The field may carry the reference WITHOUT the award's letter: a French
// operator writes "74" in STATE while the DDFM codes are "D74". Prefix is
// exactly what that case is for, so try the prefixed form HERE — applying
// it after the lookup (as the blanket pass below used to) could never
// help, because the lookup is the step that failed. Without this, the
// only way to match a bare department was to write a regex, in a mode
// where the operator had chosen "code" and not "pattern".
if prefix != "" {
if _, ok := rl.byCode[prefix+tok]; ok {
found = append(found, prefix+tok)
}
} }
} }
for _, code := range rl.withPattern { for _, code := range rl.withPattern {
@@ -839,7 +858,7 @@ func searchOne(field, matchBy string, re *regexp.Regexp, exact bool, leading, tr
// counts each reference separately. // counts each reference separately.
found = splitRefs(raw) found = splitRefs(raw)
} }
if prefix != "" { if prefix != "" && !codesAreFinal {
for i := range found { for i := range found {
found[i] = prefix + found[i] found[i] = prefix + found[i]
} }
+81
View File
@@ -0,0 +1,81 @@
package award
import (
"testing"
"hamlog/internal/qso"
)
// ddfmLike is a small stand-in for the French departments award: predefined
// references whose codes carry a letter the operator does not type.
func ddfmLike() []Def {
return []Def{{
Code: "DDFM", Name: "Departments", Type: TypeQSOFields,
Field: "state", MatchBy: "code", Prefix: "D",
}}
}
func ddfmRefs() map[string][]RefMeta {
return map[string][]RefMeta{"DDFM": {
{Code: "D29", Name: "Finistère", Valid: true},
{Code: "D49", Name: "Maine-et-Loire", Valid: true},
{Code: "D74", Name: "Haute-Savoie", Valid: true},
}}
}
func refsOf(t *testing.T, defs []Def, q qso.QSO) []string {
t.Helper()
res := Compute(defs, []qso.QSO{q}, ddfmRefs(), nil)
if len(res) != 1 {
t.Fatalf("want 1 result, got %d", len(res))
}
var out []string
for _, r := range res[0].Refs {
if r.Worked {
out = append(out, r.Ref)
}
}
return out
}
// The reported case: the operator writes just "74" in STATE, the award's codes
// are "D74", match-by is "code" and a Prefix of "D" is set. That found nothing —
// the prefix was applied only AFTER the list lookup, i.e. after the step that
// had already failed — so the only workaround was a regex, in a mode where the
// operator had explicitly chosen "code" rather than "pattern".
func TestPrefixCompletesABareReference(t *testing.T) {
got := refsOf(t, ddfmLike(), qso.QSO{Callsign: "F5AYE", State: "74"})
if len(got) != 1 || got[0] != "D74" {
t.Errorf("bare state 74 with prefix D → %v, want [D74]", got)
}
}
// And a field that ALREADY holds the whole code must not be prefixed twice.
// The blanket pass turned "D74" into "DD74" whenever a prefix was configured.
func TestPrefixDoesNotDoubleUpOnACompleteCode(t *testing.T) {
got := refsOf(t, ddfmLike(), qso.QSO{Callsign: "F5AYE", State: "D74"})
if len(got) != 1 || got[0] != "D74" {
t.Errorf("state D74 with prefix D → %v, want [D74]", got)
}
}
// A token that is neither a code nor a prefixable one stays unmatched: the
// prefix must not invent references.
func TestPrefixDoesNotInventReferences(t *testing.T) {
if got := refsOf(t, ddfmLike(), qso.QSO{Callsign: "F5AYE", State: "99"}); len(got) != 0 {
t.Errorf("unknown department 99 → %v, want none", got)
}
}
// Without a prefix nothing changes: a bare number matches nothing, a full code
// matches itself.
func TestNoPrefixKeepsExactCodeMatching(t *testing.T) {
defs := ddfmLike()
defs[0].Prefix = ""
if got := refsOf(t, defs, qso.QSO{Callsign: "F5AYE", State: "74"}); len(got) != 0 {
t.Errorf("no prefix, state 74 → %v, want none", got)
}
if got := refsOf(t, defs, qso.QSO{Callsign: "F5AYE", State: "D74"}); len(got) != 1 || got[0] != "D74" {
t.Errorf("no prefix, state D74 → %v, want [D74]", got)
}
}