Setono / editorjs-php

PHP SDK for the https://editorjs.io editor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Image Block Hydrator is Throwing Coercion error

levizwannah opened this issue · comments

When I don't add image to the editor.js content, the renderer works fine, but when I do, it throws this error Could not coerce "null" to type "string".

JSON content: {
"time": 1678954725311,
"blocks": [
{
"id": "kJ2vCYiNgz",
"type": "header",
"data": {
"text": "Frequently Asked Questions",
"level": 2
}
},
{
"id": "ZxquWEE-Wp",
"type": "paragraph",
"data": {
"text": "1. How are you doing"
}
},
{
"id": "i7RJPTu06N",
"type": "paragraph",
"data": {
"text": "I am doing nothing"
}
},
{
"id": "YGZdixLW0f",
"type": "image",
"data": {
"file": {
"url": "http://127.0.0.1:8000/pages/images/202303160818Management-consulting-in-Iran-1.jpg"
},
"caption": "",
"withBorder": false,
"stretched": false,
"withBackground": false
}
}
],
"version": "2.26.5"
}

I found the issue. When you don't pass a caption value, it is automatically taken as null, which the Type/string() tries to coerce and hence the error. I have spent like 20mins looking through the package's code. Please look at that, for now, I will try to do some tricks to fix the null value.

Hi, @levizwannah

Thanks for reporting this. Could you provide a failing test or better yet a PR with failing test + fix? :)

Btw., how do you get null in the first place? I can see your json has "" for the caption key...

Here is your JSON decoded with PHP: https://3v4l.org/iBCrU

Will close this now. I have just tagged a new alpha release of the 1.x branch: https://github.com/Setono/editorjs-php/releases/tag/v1.0.0-alpha