Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
[#544](https://github.com/nextcloud/cookbook/pull/544/) @seyfeb
- Refreshing left navigation pane after downloading recipe data, closes #465
[#547](https://github.com/nextcloud/cookbook/pull/547/) @seyfeb
- Check for existing `@context` setting in json checker
[#554](https://github.com/nextcloud/cookbook/pull/554) @christianlupus

### Removed
- Removal of old contoller no longer in use
Expand Down
5 changes: 5 additions & 0 deletions lib/Service/JsonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function isSchemaObject($obj, string $type = null) : bool {
return false;
}

if (!isset($obj['@context']) || ! preg_match('@^https?://schema\.org/?$@', $obj['@context'])) {
// We have no correct context property
return false;
}

if (!isset($obj['@type'])) {
// Objects must have a property @type
return false;
Expand Down
27 changes: 26 additions & 1 deletion tests/Unit/Service/JsonServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@ public function testIsSchemaObject() {
$result = $this->service->isSchemaObject($testData);
self::assertFalse($result, 'The object must be an array');

// Objects must have a property @context
$testData = [
"@type" => "Recipe",
"name" => "Schema.org Ontology",
"subjectOf" => [
"@type" => "Book",
"name" => "The Complete History of Schema.org"
]
];
$result = $this->service->isSchemaObject($testData);
self::assertFalse($result, 'The object must have a context');

// Context must be in schema.org domain
$testData = [
"@context" => "https://schema.com/",
'@type' => 'Recipe',
"name" => "Schema.org Ontology",
"subjectOf" => [
"@type" => "Book",
"name" => "The Complete History of Schema.org"
]
];
$result = $this->service->isSchemaObject($testData);
self::assertFalse($result, 'The object must be in the correct context');

// Objects must have a property @type
$testData = [
"@context" => "https://schema.org/",
Expand All @@ -33,7 +58,7 @@ public function testIsSchemaObject() {
];
$result = $this->service->isSchemaObject($testData);
self::assertFalse($result, 'The object must have the property @type');

// No typecheck will be requested
$testData = [
"@context" => "https://schema.org/",
Expand Down