Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/Service/RecipeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function checkRecipe(array $json): array
$json['@type'] = 'Recipe';

// Make sure that "name" doesn't have any funky characters in it
$json['name'] = $this->cleanUpString($json['name']);
$json['name'] = $this->cleanUpString($json['name'], false, true);

// Make sure that "image" is a string of the highest resolution image available
if (isset($json['image']) && $json['image']) {
Expand Down Expand Up @@ -275,7 +275,7 @@ public function checkRecipe(array $json): array
$ingredients = [];

foreach ($json['recipeIngredient'] as $i => $ingredient) {
$ingredient = $this->cleanUpString($ingredient);
$ingredient = $this->cleanUpString($ingredient, false);

if (!$ingredient) {
continue;
Expand Down Expand Up @@ -1142,7 +1142,7 @@ private function isRecipeFile($file)
*
* @return string
*/
private function cleanUpString($str, $preserve_newlines = false)
private function cleanUpString($str, $preserve_newlines = false, $remove_slashes = false)
{
if (!$str) {
return '';
Expand All @@ -1154,8 +1154,14 @@ private function cleanUpString($str, $preserve_newlines = false)
$str = str_replace(["\r", "\n"], '', $str);
}

$str = str_replace(["\t", "\\", "/"], '', $str);

//We want to remove forward-slashes for the name of the recipe, to tie it to the directory structure, which cannot have slashes
if ($remove_slashes) {
$str = str_replace(["\t", "\\", "/"], '', $str);
}
else {
$str = str_replace(["\t", "\\"], '', $str);
}

$str = html_entity_decode($str);

return $str;
Expand Down