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

Trim White space, sanitize url #601

Closed
wants to merge 3 commits into from

Conversation

StrawberryCalpico
Copy link
Contributor

Description

Screen Shot 2023-11-08 at 4 31 54 PM

Related PRS (if any):

N/A

Main changes explained:

Add third party library to sanitize and trim urls received by userprofileController

How to test:

  1. check into current branch
  2. do npm install and ... to run this PR locally
  3. use postman to test the api http://localhost:4500/api/userProfile/ {your user id here}
  4. check that white space in user lastname and firstname are ignored
  5. check that white space in url are also ignored
  6. check that empty url name will receive an error

Screenshots or videos of changes:

Before:

Bug.mp4

After:

FixNameWhiteSpace.mp4
FixUrl.mp4

Notes

can get the payload of the http request from chrome developer tools by opening the network tab, send an request, and in the payload section, click view source. Then copy it and paste it into postman body->raw

@palakgosalia
Copy link

palakgosalia commented Nov 11, 2023

Hey, I reviewed your PR and also tested it. It works as intended. I tried to add space between the name and URL and after saving and refreshing, it removed all the white spaces. I also tried the same using POST put and get request and was able to see the same results. Great work. Thank you.

601.mp4

Copy link

@KurtisIvey KurtisIvey left a comment

Choose a reason for hiding this comment

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

Great job on making the backend a little more robust. It's a welcomed improvement for sure on ensuring proper data validation. I just had some small suggestions as I work down from the userProfileRouter.js

/userProfile

  • I wouldn't recommend implementing that .replace method here that removes every bit of whitespace as some users may have two parts to their first name or last name such as "Bobby Joe". This .replace would turn that into BobbyJoe. However, I definitely understand the intention, and would instead recommend using .trim(). This will remove any unnecessary leading or trailing whitespace without removing any intended whitespace.

Screenshot 2023-12-01 at 6 29 43 PM

/userProfile/:userId

  • same thing as the suggestion noted above but only applying it to "firstName" and "lastName".
  • I think the custom sanitizer is a great use for the personal links, but I would suggest removing the .replace(/\s/g, "") from the "Name" variable and instead opting for a .trim() due to some websites having multiple words in them. Keep the .replace in the link though as that is a fantastic implementation.

Screenshot 2023-12-01 at 6 35 31 PM

Other than that, the linter is lighting up like a christmas tree and customSanitizer is an unused variable that can be removed since it's chained to .body.
Screenshot 2023-12-01 at 6 43 09 PM

Screenshot 2023-12-01 at 6 38 31 PM

Apologies for the background noise, my wife is watching House of villains lol...
https://github.com/OneCommunityGlobal/HGNRest/assets/19482363/b186eba6-7139-46ee-8fee-1fab73f82528

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