Skip to content

Commit 118b0c9

Browse files
committed
fix checksum validation in parseHistoricDataset
1 parent 3c15a2c commit 118b0c9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func parseHistoricDataset(dataset string) (Dataset, error) {
104104
data := parts[1]
105105
checksum := parts[2]
106106

107-
valid := verifyChecksum(label+" "+data, checksum)
107+
valid := verifyChecksum(checksum, label+" "+data)
108108
return Dataset{Label: label, Data: data, Valid: valid, Checksum: checksum}, nil
109109
}
110110

parser_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func TestParseHistoricDataset(t *testing.T) {
4747
if dataset.Data != "012345678901" {
4848
t.Errorf("Expected data 012345678901, got %s", dataset.Data)
4949
}
50+
51+
if dataset.Valid != true {
52+
t.Errorf("Checksum invalid: %s", dataset.Checksum)
53+
}
5054
}
5155

5256
func TestParseStandardDataset(t *testing.T) {
@@ -63,14 +67,19 @@ func TestParseStandardDataset(t *testing.T) {
6367
if dataset.Data != "BASE" {
6468
t.Errorf("Expected data BASE, got %s", dataset.Data)
6569
}
70+
71+
if dataset.Valid != true {
72+
t.Errorf("Checksum invalid: %s", dataset.Checksum)
73+
}
6674
}
6775

6876
func TestCalculateChecksum(t *testing.T) {
6977
tests := []struct {
7078
input string
7179
expected string
7280
}{
73-
{"IINST 002", "Y"}, // historical format
81+
{"IINST 002", "Y"}, // historical format
82+
{"IMAX 090", "H"},
7483
{"IINST\t002", "B"}, // standard format
7584
}
7685

0 commit comments

Comments
 (0)