payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
22.08k stars 1.34k forks source link

`REST` api throws `NotFound` if custom `id` contains `/` symbol #7021

Closed Fitch24 closed 1 week ago

Fitch24 commented 3 weeks ago

Link to reproduction

No response

Describe the Bug

When custom id contains / symbol all id-specified operations /api/{collection-slug}/{id} throws NotFound error in REST-api.

To Reproduce

Payload Version

2.23.1

Adapters and Plugins

db-mongodb

rafalnawojczyk commented 3 weeks ago

I'm not sure, but it looks like it can be pretty hard to fix. It's a part of URL, so next API route is catching it as a separate routes and is looking for handlers for foo(it's an ID for API) and bar(it's a separate route inside foo).

It's kind of agains REST API rules to have any ID's for routes with / when it is not the last route.

Maybe you could try to rewrite your logic to use underscore or hyphen with a help of a conversion util.

Fitch24 commented 3 weeks ago

Thanks for your reply. I'm not using / in id. I just find out it accidentally when create element with / in id via admin UI and then got NotFound page. So I created the issue because it's unexpected and undocumented behavior. I agree, it's hard to fix (and unnecessary). You can close this issue. And may be, you can add a note to the cusmozible id documentation (about some symbols in id can break some REST-api operations).

paulpopus commented 1 week ago

Thanks both! We'll make sure this is documented for v2 and v3