Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array to string conversion #25

Closed
reefki opened this issue Jun 29, 2022 · 8 comments · Fixed by #39 or marvinosswald/tiptap-php#1
Closed

Array to string conversion #25

reefki opened this issue Jun 29, 2022 · 8 comments · Fixed by #39 or marvinosswald/tiptap-php#1

Comments

@reefki
Copy link

reefki commented Jun 29, 2022

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>
@anonim1133
Copy link

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

@robertdrakedennis
Copy link

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

@Somethingideally
Copy link

Same issue

@scottmetoyer
Copy link

scottmetoyer commented Feb 12, 2023

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.

@marvinosswald
Copy link

marvinosswald commented May 31, 2023

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

@godismyjudge95
Copy link
Contributor

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 🤞

@enkay
Copy link

enkay commented Mar 11, 2024

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

On version 1.3.0

@marvinosswald
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants