Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package quickfix

import (
"bytes"

"github.com/quickfixgo/quickfix/datadictionary"
)

Expand Down Expand Up @@ -385,10 +387,21 @@ func validateField(d *datadictionary.DataDictionary,
return nil
}

allowedValues := d.FieldTypeByTag[int(field.tag)].Enums
allowedValues := fieldType.Enums
if len(allowedValues) != 0 {
if _, validValue := allowedValues[string(field.value)]; !validValue {
return ValueIsIncorrect(field.tag)
switch fieldType.Type {
case "MULTIPLESTRINGVALUE", "MULTIPLEVALUESTRING", "MULTIPLECHARVALUE":
// These fields carry a space-delimited set of enum tokens, each of
// which must be individually valid (e.g. ExecInst "1 5" = two enums).
for _, component := range bytes.Split(field.value, []byte{' '}) {
if _, validValue := allowedValues[string(component)]; !validValue {
return ValueIsIncorrect(field.tag)
}
}
default:
if _, validValue := allowedValues[string(field.value)]; !validValue {
return ValueIsIncorrect(field.tag)
}
}
}

Expand Down
38 changes: 38 additions & 0 deletions validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func TestValidate(t *testing.T) {
tcCheckUserDefinedFieldsDisabled(),
tcCheckUserDefinedFieldsDisabledFixT(),
tcMultipleRepeatingGroupFields(),
tcMultiValueEnumValid(),
tcMultiValueEnumInvalidComponent(),
}

msg := NewMessage()
Expand Down Expand Up @@ -662,6 +664,42 @@ func tcValueIsIncorrectFixT() validateTest {
}
}

func tcMultiValueEnumValid() validateTest {
dict, _ := datadictionary.Parse("spec/FIX43.xml")
validator := NewValidator(defaultValidatorSettings, dict, nil)

// ExecInst (tag 18) is a MULTIPLEVALUESTRING: a space-delimited set of
// individually-valid enum tokens (e.g. "Y M") must be accepted.
builder := createFIX43NewOrderSingle()
builder.Body.SetField(Tag(18), FIXString("Y M"))
msgBytes := builder.build()

return validateTest{
TestName: "Multi-value enum valid",
Validator: validator,
MessageBytes: msgBytes,
DoNotExpectReject: true,
}
}

func tcMultiValueEnumInvalidComponent() validateTest {
dict, _ := datadictionary.Parse("spec/FIX43.xml")
validator := NewValidator(defaultValidatorSettings, dict, nil)

tag := Tag(18)
builder := createFIX43NewOrderSingle()
builder.Body.SetField(tag, FIXString("Y ZZ")) // ZZ is not a valid ExecInst enum
msgBytes := builder.build()

return validateTest{
TestName: "Multi-value enum invalid component",
Validator: validator,
MessageBytes: msgBytes,
ExpectedRejectReason: rejectReasonValueIsIncorrect,
ExpectedRefTagID: &tag,
}
}

func tcIncorrectDataFormatForValue() validateTest {
dict, _ := datadictionary.Parse("spec/FIX40.xml")
validator := NewValidator(defaultValidatorSettings, dict, nil)
Expand Down
Loading