nextcloud / nextcloud/cookbook

JSON-LD parser crashes when @context is an object

Open
#2,914 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

website support
Dominant language
HTML
Stars
641
Forks
113
Avg merge
21h 31m
Merged PRs (30d)
26

Description

Failing website: https://kuchniastudenta.pl/obiady-i-kolacje-dla-studentow/potrawka-z-makaronem-orzo-i-ciecierzyca

Checking if valid metadata are present:

Yes, the website has the correct metadata.

Cookbook version: 0.11.5

Problem description (if applicable):

The page cannot be imported. The error message is:

[index] Error: OCA\Cookbook\Service\JsonService::isSchemaContext(): Argument #1 ($context) must be of type string, array given, called in /var/www/html/custom_apps/cookbook/lib/Helper/HTMLParser/HttpJsonLdParser.php on line 132 in file '/var/www/html/custom_apps/cookbook/lib/Service/JsonService.php' line 74

My guess from looking at the failing code is that the importer is crashing on an Organization object with an embedded object inside @context, while the code assumes that it's always a string:

<script type="application/ld+json">
{
  "@context": {
    "@vocab": "http://schema.org/"
  },
  "@graph": [
    {
      "@type": "Organization",
      "name": "Kuchnia Studenta",
      "url": " https://kuchniastudenta.pl",
      "logo": "https://kuchniastudenta.pl/upload/config_photos/kuchnia-studenta-65f364b430a0d.png"
    }
  ]
}
</script>

I guess this is somewhat related to #1675, but in this case the problem could be resolved by just skipping unparsable JSON-LD objects, as the recipe itself doesn't use @graph:

Recipe object
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Recipe",
  "datePublished": "2025-03-31",
  "description": "Ta pożywna potrawa dostarcza solidną dawkę białka oraz błonnika, co sprzyja sytości i wspiera trawienie. Dzięki ciecierzycy i szpinakowi jest bogata w żelazo, magnez i witaminy z grupy B, wspomagające energię i funkcjonowanie układu nerwowego. Zdrowe tłuszcze z oliwy oraz warzywa pełne antyoksydantów pomagają w walce ze stanami zapalnymi i wspierają odporność. ",
  "image": "https://kuchniastudenta.pl/photos/2025/03/20250331-142720-67ea935b4b743.webp",
  "recipeIngredient": [
    "1 łyżka oliwy/oleju",
    "1 spora cebula",
    "2 ząbki czosnku",
    "1 mała marchewka",
    "1 dość mała cukinia",
    "1 łyżeczka papryki słodkiej w proszku",
    "0.5 łyżeczki bazylii",
    "300 g ciecierzycy ze słoika lub puszki (po odsączeniu)",
    "500 ml gorącego bulionu (u nas woda z bulionem ze słoiczka)",
    "2 łyżki koncentratu pomidorowego",
    "0.5 szklanki makaronu orzo (ok 100 g)",
    "2 garście szpinaku (50 g)",
    "1 łyżka serka śmietankowego typu Almette",
    "opcjonalnie natka pietruszki do dekoracji"
  ],
  "name": "Potrawka z makaronem orzo i ciecierzycą",
  "recipeCategory": "Obiady i kolacje dla studentów",
  "recipeYield": "3",
  "nutrition": {
    "@type": "NutritionInformation",
    "calories": "410",
    "fatContent": "8",
    "carbohydrateContent": "69",
    "proteinContent": "16",
    "fiberContent": "10",
    "servingSize": 3
  },
  "recipeInstructions": [
    {
      "@type": "HowToStep",
      "text": "Cebulę obierz i pokrój w piórka lub kostkę. Wrzuć ją na rozgrzaną patelnię z oliwą/olejem."
    },
    {
      "@type": "HowToStep",
      "text": "W tym czasie stopniowo przygotowuj i dodawaj kolejno na patelnię pozostałe składniki: czosnek przeciśnięty przez praskę, marchewkę startą na tarce lub pokrojoną w drobną kosteczkę, cukinię obraną i pokrojoną w półplasterki. "
    },
    {
      "@type": "HowToStep",
      "text": "Kiedy dodasz wszystkie warzywa przypraw całość papryką słodką, bazylią, solą i pieprzem. Smaż całość jeszcze ok 5 min."
    },
    {
      "@type": "HowToStep",
      "text": "Odcedź i dodaj na patelnię ciecierzycę, makaron orzo oraz bulion i koncentrat pomidorowy. Doprowadź do wrzenia i gotuj bez przykrycia ok 15-20 min, do ugotowania się makaronu. W razie czego podlej całość wodą."
    },
    {
      "@type": "HowToStep",
      "text": "Na końcu dodaj szpinak i serek śmietankowy oraz ewentualnie przypraw."
    },
    {
      "@type": "HowToStep",
      "text": "Wyłóż potrawkę do miseczki i udekoruj posiekaną natką pietruszki."
    }
  ]
}
</script>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the import with the failing website, then inspect the call in lib/Helper/HTMLParser/HttpJsonLdParser.php around line 132 and JsonService.php around line 74. The importer should no longer crash on the organization JSON-LD object and should still import the separate recipe object.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.