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

chore(site launch form): trim site launch form input #698

Merged
merged 4 commits into from
Apr 17, 2023

Conversation

kishore03109
Copy link
Contributor

Problem

The form expects string values. When typing, it is possible for someone to enter a space in the string

Solution

Defensively trim all inputs

@kishore03109 kishore03109 requested a review from a team April 12, 2023 06:55
Copy link
Contributor

@alexanderleegs alexanderleegs left a comment

Choose a reason for hiding this comment

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

Actually, is defensive trimming something we should have as a default on all our methods which use formsg input? I'm thinking it might be better to trim from getField in formsg-utils instead

@kishore03109
Copy link
Contributor Author

@alexanderleegs oh hey this is fair!

Comment on lines 13 to 28
function trimAllStrings(
responseArray: string[] | string[][]
): string[] | string[][] {
if (Array.isArray(responseArray)) {
responseArray.map((item) => {
if (Array.isArray(item)) {
return trimAllStrings(item)
}
if (typeof item === "string") {
return item.trim()
}
return item
})
return responseArray
}
return responseArray
Copy link
Contributor

@alexanderleegs alexanderleegs Apr 17, 2023

Choose a reason for hiding this comment

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

Thoughts on reducing the checks here, given that responseArray is string[] | string[][]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TS complains if we dont have this because it is not able to infer that
if (Array.isArray(responseArray)), then responseArray is of type []. I have added in a comment for clarity here:
08433bb

Comment on lines 36 to 40
let answers = response?.answerArray
if (answers) {
answers = trimAllStrings(answers)
}
return response?.answerArray
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking - does this modify response? I think it might be better to rewrite it so it's clearly regardless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, this is a bug, fixed here 08433bb

Copy link
Contributor

@alexanderleegs alexanderleegs left a comment

Choose a reason for hiding this comment

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

lgtm

@kishore03109 kishore03109 merged commit 6663192 into develop Apr 17, 2023
@mergify mergify bot deleted the chore/site-launch/trim-form-input branch April 17, 2023 03:54
@alexanderleegs alexanderleegs mentioned this pull request Apr 17, 2023
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.

2 participants