-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Validate product and collection handles to be URL safe #7310
Conversation
|
@thetutlage is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
This is my first PR. So please feel free to familiarise me to the process and let me know if something needs to changed or done in a different way. Also, I wasn't table to find any tests for the validators (maybe I looked at wrong places). So please guide me on how/where to write tests |
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.
💪🏻
Good work with the validators - I'd expect these checks to happen further down the stack too. E.g., calling Also, there is some logic somewhere that constructs a handle from the title, not sure if it's in the admin code or somewhere else. Currently, this code doesn't remove disallowed characters. E.g. |
Yeah, I had this conversation on the Slack too. I did not find any sort of schema validations happening in the services, so didn't feel comfortable to put it there. But, if the goal is to keep formatting validations at the service layer. I can surely move the logic there as a manual validation. Or should we use Zod within services as-well? |
Yeah, makes sense. The creation of handle should perform the normalization |
packages/modules/product/src/services/product-module-service.ts
Outdated
Show resolved
Hide resolved
packages/modules/product/src/services/product-module-service.ts
Outdated
Show resolved
Hide resolved
I ended up changing the implementation
Let me know if the implementation looks right. If yes, I will repeat it for collections and other entities as well. |
I believe this might be due to the upert with replace, @sradevski what do you think? I believe the reason is that an obj ref might be assigned at different level creating a circular ref on jsonifying it |
I got the error fixed after this commit ae4d9a7 Seems like removing the handle generation from the model hook breaks something and the error stack isn't able to point at it. I am not sure if I should remove the model hook or not. Because we have the same logic in service also and I remove the logic from service, then some other parts of the application break. |
@riqwan I shared the reasoning about the CI failing earlier in this comment. #7310 (comment) |
packages/modules/product/src/services/product-module-service.ts
Outdated
Show resolved
Hide resolved
packages/modules/product/src/services/product-module-service.ts
Outdated
Show resolved
Hide resolved
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.
Just need to fix the pipeline 💪 good work
Fixes: CORE-2072
I am wondering if we need the handle to be URL-safe, for example: We got the product URL In this PR, the handle removes all non-alphanumeric characters, so we can not use I suggest to remove this line |
@jackjyq thanks for bringing it up. I agree, we went with a very restrictive check for URL-safety. Although we do want to handle this in the BE, we probably want to revisit the Regex we use for the check. I'll open a ticket internally to track this and tackle it before the public v2 release. |
This PR validates the Product and the Collection handles to be URL safe using a Regex. Consult the following screenshot to see what is allowed
Update
Ended up moving the normalization and validation both to the service. Also tested manually with the admin panel and following are the results.
A title with
@
in it generates correct handleThe backend returns error when handle it manually updated to contain invalid characters.
However, in this case frontend isn't showing errors. Something should be handled in a separate issue.