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: Validate and Trim Spaces for All User Input Fields #195

Open
bupd opened this issue Sep 18, 2024 · 2 comments
Open

Chore: Validate and Trim Spaces for All User Input Fields #195

bupd opened this issue Sep 18, 2024 · 2 comments
Labels
good first issue Good for newcomers

Comments

@bupd
Copy link
Collaborator

bupd commented Sep 18, 2024

Expected Outcome

  • All input fields should properly validate and trim spaces.
  • If an input field contains only spaces or empty it should trigger an appropriate error message.

You can make use of Validation method mentioned here.

@bupd bupd added the good first issue Good for newcomers label Sep 18, 2024
@JianMinTang
Copy link

Hi, @bupd, I'm interested in this issue and have two ideas to solve the input problem.
I'm not sure which one is better.
The first one is:
harborcli-#195-1
The second one is:
harborcli-#195-2
And I'm not clear about the rules for trimming the string of input, do I need to trim only the leading of spaces, only the trailing of spaces, both the leading and trailing of spaces? Or are there other rules?
I'd really appreciate any additional helpful ideas you have to share!

@bupd
Copy link
Collaborator Author

bupd commented Sep 20, 2024

Hello @JianMinTang, thanks for your interest in addressing this issue.

And I'm not clear about the rules for trimming the string of input, do I need to trim only the leading of spaces, only the trailing of spaces, both the leading and trailing of spaces? Or are there other rules?

Regarding your question on trimming the input string:
The Go method strings.TrimSpace will indeed trim both leading and trailing whitespaces. This should work well for cleaning up the input.

Here's my suggested approach to handle this across all user input fields:

  • Step 1: Use strings.TrimSpace to remove both leading and trailing spaces from the input.
  • Step 2: Check if the resulting string is empty, and if so, return an appropriate error.
  • Additional Step: You can also apply more formatting rules & appropriate error messages as needed for specific fields to ensure the input adheres to the expected API resource model.

For reference, please take a look at the implementation in this PR review. You can replicate the pattern used there for all relevant input fields. That's exactly the kind of input validation we need to implement throughout.

Feel free to share any further thoughts or ideas you might have!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants