-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix padWorkflowName()
#977
Conversation
neededBytes := append(b, make([]byte, 10-len(b))...) | ||
m.WorkflowName = hex.EncodeToString(neededBytes) | ||
} else if len(m.WorkflowName) < 10 { | ||
// Pad with spaces | ||
suffix := strings.Repeat(" ", 10-len(m.WorkflowName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should never be the case. You also don't really have to hex-decode. Just pad with "0" chars up to length 20.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @krehermann - cap_encoder.go in core validates that and fails it it's not a valid hex string that decodes to 10 bytes. We should require it here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. if it's got to be that then let's move the validation to this struct. can be a follow up change.
code comments aren't sufficient if there are restrictions on the values. and doesn't make sense to have validation far away in a different repo. @vyzaldysanchez can you do that as a follow up (write a Validate method for this struct)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thing!
} | ||
|
||
// the contract requires exactly 10 bytes for the workflow name | ||
// the json schema allows for a variable length string <= len(10) | ||
// pad with trailing spaces to meet the contract requirements | ||
// the resulting workflow name should be up to 10 bytes long |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did this change? i don't think it's correct
fields: fields{ | ||
WorkflowName: "not-hex", | ||
}, | ||
want: "not-hex0000000000000", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol, technically correct ;)
Requires
Supports