added preserve_slashes functionality to cleanUpString, so we may have slashes in fractional ingredieents, issue # 262

This commit is contained in:
Tim Andrews 2020-06-18 22:44:31 -04:00
Родитель a719b7b1a6
Коммит 5f1a55d06b
1 изменённых файлов: 9 добавлений и 4 удалений

Просмотреть файл

@ -275,7 +275,7 @@ class RecipeService
$ingredients = []; $ingredients = [];
foreach ($json['recipeIngredient'] as $i => $ingredient) { foreach ($json['recipeIngredient'] as $i => $ingredient) {
$ingredient = $this->cleanUpString($ingredient); $ingredient = $this->cleanUpString($ingredient, false, true);
if (!$ingredient) { if (!$ingredient) {
continue; continue;
@ -1142,7 +1142,7 @@ class RecipeService
* *
* @return string * @return string
*/ */
private function cleanUpString($str, $preserve_newlines = false) private function cleanUpString($str, $preserve_newlines = false, $preserve_slashes = false)
{ {
if (!$str) { if (!$str) {
return ''; return '';
@ -1154,8 +1154,13 @@ class RecipeService
$str = str_replace(["\r", "\n"], '', $str); $str = str_replace(["\r", "\n"], '', $str);
} }
$str = str_replace(["\t", "\\", "/"], '', $str); if (!$preserve_slashes) {
$str = str_replace(["\t", "\\"], '', $str);
}
else {
$str = str_replace(["\t", "\\", "/"], '', $str);
}
$str = html_entity_decode($str); $str = html_entity_decode($str);
return $str; return $str;