lanthaler / JsonLD

JSON-LD processor for PHP
MIT License
335 stars 62 forks source link

relativ schema URL fail #71

Closed vvh-empora closed 8 years ago

vvh-empora commented 8 years ago

Input Data:

[{"@context":"http:\/\/schema.org","@type":"Product","name":"Nike Internationalist Premium sneakers","description":"We love these 'Internationalist Premium' sneakers to add a touch of urban cool to any outfit. The understated dotted black print is accented with panels of grey beige suede and sleek black detailing. Wear yours with denim for effortless weekend style.","color":["black","grey","neutrals"],"manufacturer":"Nike","sku":"P00179370","url":"http:\/\/www.mytheresa.com\/en-us\/nike-internationalist-premium-sneakers-540297.html","image":"\/\/img.mytheresa.com\/544\/544\/90\/jpeg\/catalog\/product\/5b\/P00179370.jpg","brand":{"@type":"Brand","name":"Nike","image":"","url":"http:\/\/www.mytheresa.com\/en-us\/designers\/nike.html"},"offers":{"@type":"Offer","availability":"http:\/\/schema.org\/InStock","price":111,"priceCurrency":"USD"},"isConsumableFor":[{"@context":"http:\/\/schema.org","@type":"Product","name":"Oz Indigo Icon denim jacket","description":null,"color":false,"manufacturer":"Marc by Marc Jacobs","sku":"P00147790","url":null,"image":"\/\/img.mytheresa.com\/544\/544\/90\/jpeg\/catalog\/product\/2d\/P00147790--STANDARD.jpg","brand":{"@type":"Brand","name":"Marc by Marc Jacobs","image":"","url":"http:\/\/www.mytheresa.com\/en-us\/catalog\/category\/view\/"},"offers":{"@type":"Offer","availability":"http:\/\/schema.org\/OutOfStock","price":"233.0000","priceCurrency":"USD"}},{"@context":"http:\/\/schema.org","@type":"Product","name":"Mid-Rise Skinny Leg jeans","description":null,"color":false,"manufacturer":"J Brand","sku":"P00162664","url":null,"image":"\/\/img.mytheresa.com\/544\/544\/90\/jpeg\/catalog\/product\/db\/P00162664.jpg","brand":{"@type":"Brand","name":"J Brand","image":"","url":"http:\/\/www.mytheresa.com\/en-us\/catalog\/category\/view\/"},"offers":{"@type":"Offer","availability":"http:\/\/schema.org\/OutOfStock","price":"284.0000","priceCurrency":"USD"}},{"@context":"http:\/\/schema.org","@type":"Product","name":"Printed cotton T-shirt","description":null,"color":false,"manufacturer":"\u00catre C\u00e9cile","sku":"P00162707","url":null,"image":"\/\/img.mytheresa.com\/544\/544\/90\/jpeg\/catalog\/product\/eb\/P00162707.jpg","brand":{"@type":"Brand","name":"\u00catre C\u00e9cile","image":"","url":"http:\/\/www.mytheresa.com\/en-us\/catalog\/category\/view\/"},"offers":{"@type":"Offer","availability":"http:\/\/schema.org\/OutOfStock","price":"90.0000","priceCurrency":"USD"}}]},{"@context":"http:\/\/schema.org","@type":"Organization","name":"mytheresa.com","url":"http:\/\/www.mytheresa.com\/","contactPoint":{"@type":"ContactPoint","telephone":"1-888-550-9675","contactType":"customer service"},"sameAs":["https:\/\/twitter.com\/mytheresa_com","https:\/\/www.pinterest.com\/mytheresacom\/","https:\/\/www.facebook.com\/mytheresa"]},{"@context":"http:\/\/schema.org","@type":"WebSite","name":"mytheresa.com","url":"http:\/\/www.mytheresa.com\/","potentialAction":{"@type":"SearchAction","target":"http:\/\/www.mytheresa.com\/en-us\/catalogsearch\/result\/?q={search_term}","query-input":"required name=search_term"}},{"@context":"http:\/\/schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"http:\/\/www.mytheresa.com\/en-us\/","name":"Home"}},{"@type":"ListItem","position":2,"item":{"@id":"http:\/\/www.mytheresa.com\/en-us\/designers\/nike.html","name":"Nike"}},{"@type":"ListItem","position":3,"item":{"@id":"http:\/\/www.mytheresa.com\/en-us\/shoes.html","name":"Shoes"}},{"@type":"ListItem","position":4,"item":{"@id":"http:\/\/www.mytheresa.com\/en-us\/shoes\/sneakers.html","name":"Sneakers"}},{"@type":"ListItem","position":5,"item":{"@id":null,"name":"Nike Internationalist Premium sneakers"}}]}]

running code:

$expanded = JsonLD::expand($jsonLD);

inside the first product object, i get this as image URL:

[{"@context"://img.mytheresa.com/544/544/90/jpeg/catalog/product/5b/P00179370.jpg

the coresponding JSON is this:

"image":"\/\/img.mytheresa.com\/544\/544\/90\/jpeg\/catalog\/product\/5b\/P00179370.jpg"

so relativ URLs to schema are broken?

lanthaler commented 8 years ago

Assuming that $jsonLD in your snippet is the string that you posted above and not a URL, it works as expected. The processor has no base URL, so how could it possibly infer the protocol? You can set the base by passing it as an option

$expanded = JsonLD::expand($jsonLD, array('base' => 'http://www.mytheresa.com/'));

P.S.: It generally helps if you format code and reduce the example as much as possible.

lanthaler commented 8 years ago

I'm closing this issue now. Feel free to reopen if you think this doesn't work as expected (as described in my previous comment).

vvh-empora commented 8 years ago

hmmm... but by default set an json snippet fragment as "base" ? -> '[{"@context":' thats not what i expect...