sourceopt icon indicating copy to clipboard operation
sourceopt copied to clipboard

Fatal Error: in file /html/typo3/typo3conf/ext/sourceopt/Classes/Service/CleanHtmlService.php, line 331:

Open kurtkk opened this issue 4 months ago • 8 comments

In only ONE project I get the following error in all pages. I do not know why. There must be something in the source-code that creates that error. See the screenshots I made:

Image

and

Image

kurtkk avatar Jul 10 '25 09:07 kurtkk

please provide the output of var_dump($html) @ [326] & [328]

xerc avatar Jul 10 '25 12:07 xerc

Hey @xerc ,

if the "return $html" do not result in an error, $html will be a valid string. But the return type of the preg_replace is null. That means there is an internal error in the replacement?!

@kurtkk Do you have more details or logs?

Regards, Tim

lochmueller avatar Jul 10 '25 12:07 lochmueller

@kurtkk Please also add EXT:sourceopt version and TYPO3 version.

lochmueller avatar Jul 10 '25 12:07 lochmueller

Sorry, I forgot that: TYPO3 13.4.15, PHP 8.3 FPM (8.3.22) Sourceopt: 5.2.8

typo3_fff612a.log

I made a copy of the project "forgeinrichtenundwohnen.de" for further development. In this copy, with the identical DB, no error is coming up with Sourceopt: 5.2.8!?

kurtkk avatar Jul 10 '25 15:07 kurtkk

please provide the output of var_dump($html) @ [326] & [328]

I did it but the result is too large. the dump is within a loop!?

kurtkk avatar Jul 10 '25 15:07 kurtkk

dont think /u is needed @ https://github.com/lochmueller/sourceopt/commit/40c930e267a4dd0f10c7cd0828e0dabc12b75ca9#diff-3cb2417b18f7a3a43576dddc2aeed52f0d925666c81014d687fa7a90aa88824eR345 || https://github.com/lochmueller/sourceopt/blame/main/Classes/Service/CleanHtmlService.php#L328

xerc avatar Jul 10 '25 15:07 xerc

I looked into the source code of the life project (with the modified Sourceopt) and into the DEV-Copy of that project. A screenshot will show that the difference begins in line 270:

Image

kurtkk avatar Jul 10 '25 15:07 kurtkk

I made it this way:

/**
 * Remove ALL line breaks and multiple white space.
 */
protected function killLineBreaks(string $html): string
{
    $html = str_replace($this->newline, '', $html);
    $qpx = preg_replace('/\s\s+/u', ' ', $html);
    
    if (is_string($qpx)) {
        return $qpx;
    } else {
        return $html;
    }

    // ? return preg_replace('/\n|\s+(\s)/u', '$1', $html);
}

kurtkk avatar Jul 13 '25 10:07 kurtkk

@kurtkk ; might be defect utf8 char(s) @ $html ..

  if (!mb_check_encoding($html, 'UTF-8')) {
+   mb_substitute_character(0xFFFD);
+   $html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
+   return str_replace(mb_chr(0xFFFD, 'UTF-8'), '!!', $html);
  }

xerc avatar Nov 01 '25 15:11 xerc