From 76b84898f6a444afb6dee45cafa90f21333e7b39 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sat, 16 Dec 2023 09:08:50 +0100 Subject: [PATCH] lmit ingredient parser to 512 characters to prevent too complex computations --- cookbook/helper/ingredient_parser.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cookbook/helper/ingredient_parser.py b/cookbook/helper/ingredient_parser.py index f944e416..be53c21a 100644 --- a/cookbook/helper/ingredient_parser.py +++ b/cookbook/helper/ingredient_parser.py @@ -169,6 +169,9 @@ class IngredientParser: if len(ingredient) == 0: raise ValueError('string to parse cannot be empty') + if len(ingredient) > 512: + raise ValueError('cannot parse ingredients with more than 512 characters') + # some people/languages put amount and unit at the end of the ingredient string # if something like this is detected move it to the beginning so the parser can handle it if len(ingredient) < 1000 and re.search(r'^([^\W\d_])+(.)*[1-9](\d)*\s*([^\W\d_])+', ingredient):