Skip to content

Validate each token of multi-value enum fields#766

Open
vsaraikin wants to merge 1 commit into
quickfixgo:mainfrom
vsaraikin:fix/multi-value-enum-validation
Open

Validate each token of multi-value enum fields#766
vsaraikin wants to merge 1 commit into
quickfixgo:mainfrom
vsaraikin:fix/multi-value-enum-validation

Conversation

@vsaraikin

Copy link
Copy Markdown
Contributor

Fixes #754.

Fields of type MULTIPLEVALUESTRING / MULTIPLESTRINGVALUE / MULTIPLECHARVALUE carry a space-delimited set of enum tokens (per the FIX spec, e.g. ExecInst = "1 5" means NOTHELD + HELD). validateField looked the entire raw value up in the enum map:

if _, validValue := allowedValues[string(field.value)]; !validValue {
    return ValueIsIncorrect(field.tag)
}

so any legal combination of two or more values was rejected with ValueIsIncorrect ("out of range"), even though each token is individually valid. Single-value fields still passed, which masked the bug.

Fix

For the three multi-value field types, split the value on ' ' and validate every component against the enum map; all other types keep the original single-lookup path.

Testing

Added two cases to TestValidate (FIX.4.3, ExecInst tag 18, a MULTIPLEVALUESTRING):

  • "Y M" (two valid ExecInst enums) → accepted. Fails on the current code (Unexpected reject: Value is incorrect), passes with the fix.
  • "Y ZZ" (one valid, one invalid token) → still correctly rejected with ValueIsIncorrect and the right ref tag.

The full package suite passes with no regression; gofmt clean.

Note: the code generator (cmd/generate-fix/internal/template_helpers.go) has the analogous single-lookup pattern in generated per-field setters — happy to follow up on that separately if you'd like it addressed too.

MULTIPLEVALUESTRING/MULTIPLESTRINGVALUE/MULTIPLECHARVALUE fields carry a
space-delimited set of enum tokens, but validateField looked up the whole
value in the enum map, so any legal combination of two or more values (e.g.
ExecInst "1 5") was rejected as out of range. Split on space and validate
each component. Fixes quickfixgo#754.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MultipleCharValue cannot specify more than one valid enum on messages

1 participant