Skip to content

Commit

Permalink
lmit ingredient parser to 512 characters to prevent too complex compu…
Browse files Browse the repository at this point in the history
…tations
  • Loading branch information
vabene1111 committed Dec 16, 2023
1 parent 05d9718 commit 76b8489
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cookbook/helper/ingredient_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def parse(self, ingredient):
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):
Expand Down

0 comments on commit 76b8489

Please sign in to comment.