Skip to content
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

Merged
merged 5 commits into from
Dec 19, 2024
Merged

Fix padWorkflowName() #977

merged 5 commits into from
Dec 19, 2024

Conversation

vyzaldysanchez
Copy link
Contributor

Requires

Supports

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))
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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
Copy link
Contributor

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, technically correct ;)

@vyzaldysanchez vyzaldysanchez merged commit 9728444 into main Dec 19, 2024
11 checks passed
@vyzaldysanchez vyzaldysanchez deleted the bug/KS-596/pad-workflow-name branch December 19, 2024 19:57
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.

3 participants