tiptap-php icon indicating copy to clipboard operation
tiptap-php copied to clipboard

Array to string conversion

Open reefki opened this issue 3 years ago • 8 comments

Hi there,

Silly question but when I trying to get JSON from the following HTML, it throws Array to string conversion in ../vendor/ueberdosis/tiptap-php/src/Core/DOMParser.php on line 144.

<p><iframe frameborder="0" height="385" src="https://www.youtube.com/embed/xxx" width="590"></iframe></p>
<p><iframe frameborder="0" height="385" src="https://www.youtube.com/embed/yyy" width="590"></iframe></p>

reefki avatar Jun 29 '22 07:06 reefki

Have you been able to find out what was the reason of that? Have you got it fixed?

anonim1133 avatar Jul 20 '22 11:07 anonim1133

ive also started having this issue, no real leads on whats causing it, i was migrating away from the deprecated tiptap parser but i definitely cant unless i get more info on how this is occuring

robertdrakedennis avatar Aug 27 '22 23:08 robertdrakedennis

Same issue

Somethingideally avatar Sep 10 '22 08:09 Somethingideally

I'm also experiencing this issue.

It seems to be related to the this multidimensional array check failing to detect empty nested arrays as described here. Since the check fails, the array_diff that follows throws an exception as described here.

A better (although possibly slower) approach would be to check for a multidimensional array doing something like this:

private function isMultiArray( $arr ) {
   rsort( $arr );
   return isset( $arr[0] ) && is_array( $arr[0] );
}

private function mergeSimilarNodes($nodes)
{
   $result = [];
   array_reduce($nodes, function ($carry, $node) use (&$result) {

      // Ignore multidimensional arrays
      if ($this->isMultiArray($node) || $this->isMultiArray($carry))
      {
         $result[] = $node;
         return $node;
      }
      ...
   }
}

I tested this locally and it seemed to work fine. I'll see about getting a pull request put together within the next few days.

scottmetoyer avatar Feb 12 '23 23:02 scottmetoyer

Very weird, happens to me on production but not locally same php version tho. For me this was caused by my old editor wrapping img tags in an additional p tag.

PHP: 8.2.5

marvinosswald avatar May 31 '23 08:05 marvinosswald

I just encountered this while attempting to import content from WordPress - it wraps everything in p tags.

Submitted a PR with a failing test, so hopefully it gets merged soon 🤞

godismyjudge95 avatar Oct 01 '23 04:10 godismyjudge95

I'm also getting this error while parsing html, no idea what's triggering it.

On version 1.3.0

enkay avatar Mar 11 '24 21:03 enkay

@enkay I'm now quite certain this is caused by the p tag surrounding the image.

marvinosswald avatar May 03 '24 07:05 marvinosswald