[Bug]: "Trying to access array offset on null" on text 'null' value

Open Beginner friendly
#80 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start in src/Editor.php at getContentType and follow the value into src/Core/Schema.php around line 70. Reproduce the failure with SetContent using the text "null", then run the existing test suite and add a regression test if the relevant test location is available. Done means the literal text "null" can be edited without an exception.

Written by the indexing model from the issue text.

Description

bug
PHP Version

8.4.3

Version

2.0.0

Bug Description

Setting content with SetContent to text 'null' throws an error "Trying to access array offset on null" in vendor\\ueberdosis\\tiptap-php\\src\\Core\\Schema.php:70

Its because in https://github.com/ueberdosis/tiptap-php/blob/2.0.0/src/Editor.php#L45
getContentType is called https://github.com/ueberdosis/tiptap-php/blob/2.0.0/src/Editor.php#L96
and verifies the value using json_decode, but this accepts literal 'null' text as valid null

So in turn apply will get a null document https://github.com/ueberdosis/tiptap-php/blob/2.0.0/src/Core/Schema.php#L70

and throw

Expected Behavior

Be able to edit any text value, including 'null'

Additional Context (Optional)

I only found about this by chance using laravel filament RichEditor that is using this package under the hood.
The input data is external and imported to db, and there was some 'null' text in some of the fields.

Thats why there is also ready to test filament repo with this case as it was reported as filament issue here https://github.com/filamentphp/filament/issues/18216 but closed due the issue being in the package

Dependency Updates
  • Yes, I've updated all my dependencies.
Dominant language
PHP
Stars
278
Forks
46
Avg merge
4m
Merged PRs (30d)
2

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.

More from ueberdosis/tiptap-php

All issues in ueberdosis/tiptap-php

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.