mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-10-27 16:24:31 -04:00
fix: Make String Cleaner More Robust (#6032)
This commit is contained in:
@@ -75,13 +75,17 @@ def clean(recipe_data: Recipe | dict, translator: Translator, url=None) -> Recip
|
|||||||
return Recipe(**recipe_data)
|
return Recipe(**recipe_data)
|
||||||
|
|
||||||
|
|
||||||
def clean_string(text: str | list | int) -> str:
|
def clean_string(text: str | list | int | float) -> str:
|
||||||
"""Cleans a string of HTML tags and extra white space"""
|
"""Cleans a string of HTML tags and extra white space"""
|
||||||
if not isinstance(text, str):
|
if not isinstance(text, str):
|
||||||
if isinstance(text, list):
|
if isinstance(text, list):
|
||||||
text = text[0]
|
if text:
|
||||||
|
return clean_string(text[0])
|
||||||
if isinstance(text, int):
|
else:
|
||||||
|
text = ""
|
||||||
|
elif text is None:
|
||||||
|
text = ""
|
||||||
|
else:
|
||||||
text = str(text)
|
text = str(text)
|
||||||
|
|
||||||
if not text:
|
if not text:
|
||||||
|
|||||||
@@ -62,6 +62,36 @@ clean_string_test_cases = (
|
|||||||
input=1,
|
input=1,
|
||||||
expected="1",
|
expected="1",
|
||||||
),
|
),
|
||||||
|
CleanerCase(
|
||||||
|
test_id="float",
|
||||||
|
input=1.5,
|
||||||
|
expected="1.5",
|
||||||
|
),
|
||||||
|
CleanerCase(
|
||||||
|
test_id="none",
|
||||||
|
input=None,
|
||||||
|
expected="",
|
||||||
|
),
|
||||||
|
CleanerCase(
|
||||||
|
test_id="list empty",
|
||||||
|
input=[],
|
||||||
|
expected="",
|
||||||
|
),
|
||||||
|
CleanerCase(
|
||||||
|
test_id="list none",
|
||||||
|
input=[None],
|
||||||
|
expected="",
|
||||||
|
),
|
||||||
|
CleanerCase(
|
||||||
|
test_id="list multiple none",
|
||||||
|
input=[None, None],
|
||||||
|
expected="",
|
||||||
|
),
|
||||||
|
CleanerCase(
|
||||||
|
test_id="unexpected type",
|
||||||
|
input={"key": "value"},
|
||||||
|
expected="{'key': 'value'}",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user