mealie-recipes / mealie

Mealie is a self hosted recipe manager and meal planner with a RestAPI backend and a reactive frontend application built in Vue for a pleasant user experience for the whole family. Easily add recipes into your database by providing the url and mealie will automatically import the relevant data or add a family recipe with the UI editor
https://docs.mealie.io
GNU Affero General Public License v3.0
6.6k stars 678 forks source link

Recipe with a single 'space' as the title returns "404 page not found" - reproduced on the demo site #3505

Closed dino9848 closed 1 week ago

dino9848 commented 4 months ago

First Check

What is the issue you are experiencing?

Create a manual recipe on the demo site by creating a recipe titled with just a single space creates a 404 error and no way to delete or edit the issue

Steps to Reproduce

1) Click Create - select the 'create a recipe manually' 2) enter a single space in the recipe name box and click "Create"

It creates a recipe without any option to delete from the GUI. Clicking on the edit option creates the 404 error

Note: If you do this twice, the second recipe created with automatically be named "(1)" and it does allow editing and deleting. Best regards and thanks for a wonderful app.

Please provide relevant logs

No need. It happens on every version I tried. Can even be reproduced on your demo site. Would love to be able to correct my database that has one of these 'no-name can't delete' recipes

Mealie Version

No response

Deployment

Docker (Linux)

Additional Deployment Details

Running on current CasaOS

dino9848 commented 4 months ago

Able to delete from the data management admin account. Regular user can't delete.

boc-the-git commented 4 months ago

Solution here is to stop a recipe being able to be created when the title (removing whitespace) is null

nephlm commented 3 months ago

The route seems to call RecipeService.create_one() which has the following code:

https://github.com/mealie-recipes/mealie/blob/mealie-next/mealie/services/recipe/recipe_service.py#L121-L123

    def create_one(self, create_data: Recipe | CreateRecipe) -> Recipe:
        if create_data.name is None:
            create_data.name = "New Recipe"

It seems like the correct thing might be just to change that to:

    def create_one(self, create_data: Recipe | CreateRecipe) -> Recipe:
        if not create_data.name:
            create_data.name = "New Recipe"

Later code handles deduping if there are previous "New Recipe". Though the proposed changes don't handle leading/trailing spaces so it will have to be a little more complicated than that.

michael-genson commented 3 months ago

We should have a "clean string" method somewhere that handles things like that, probably with the migration code. Although honestly we should probably handle that when creating the slug since slugs already clean strings anyway