Issue Feature Closed

#106745`SVG` strips inline CSS

Marcus Förster 05/21/25, 17:21 updated 05/23/25, 13:05

Description

https://github.com/TYPO3-CMS/frontend/blob/b445d1ee8ed8a03e9012dc2c9a53021fb68fed1d/Classes/ContentObject/ScalableVectorGraphicsContentObject.php#L51-L61

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">
  <defs>
    <style>path{fill:red}</style>

=>

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">
  <defs>
    <style>path</style>

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 7

  1. Garvin Hicking changed description 05/23/25, 11:51

  2. Garvin Hicking commented and changed status New Needs Feedback 05/23/25, 11:56

    Please give more steps to reproduce this behaviour.

    The PHP code you linked to is not actually responsible for transforming this. I assume some Fluid replacement instead to happen because of the inline { and } tags?

  3. Marcus Förster commented 05/23/25, 12:00

        stdWrap.cObject = FILES
        stdWrap.cObject {
          references {
            data = levelmedia:-1
          }
          renderObj = SVG
          renderObj {
            renderMode = inline
            src.wrap = fileadmin|
            src.data = file:current:identifier
          }
        }
  4. Garvin Hicking commented 05/23/25, 12:10

    I wonder if it’s some DOMXML issue in your PHP instance. Can you run this PHP script with your SVG file and tell me your output:

    $svgContent = (string)file_get_contents($argv[1]);
    $svgContent = preg_replace('/<script[\s\S]*?>[\s\S]*?<\/script>/i', '', $svgContent) ?? '';
    $svgElement = simplexml_load_string($svgContent);
    $domXml = dom_import_simplexml($svgElement);
    // remove xml version tag
    $content = $domXml->ownerDocument->saveXML($domXml->ownerDocument->documentElement);
    echo $content;

    If I run this with this SVG:

    <svg width="100%" height="100%" viewBox="0 0 204 204" version="1.1"
         xmlns="http://www.w3.org/2000/svg"
         style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
            <defs>
                <style>path{fill:red}</style>
            </defs>
      <g>
        <circle cx="101.622" cy="101.622" r="101.622" style="fill:#ff8002;"/>
        <path
          d="M56.178,113.184l-14.506,0l-0,-21.272l14.506,0.001l0,-48.532l93.222,0l-0,21.25l-70.784,0l-0,27.269l49.318,0l0,21.275l-49.318,-0l-0,30.391l70.784,-0l-0,21.2
          style="fill:#fff;fill-rule:nonzero;"/>
      </g>
    </svg>

    I get the proper output on my CLI shell (PHP 8.4.6).

    Thanks.

  5. Marcus Förster commented 05/23/25, 12:22

    THX for the example // `renderInline` returns correct SVG so it is modf. somewhere else

  6. Marcus Förster commented 05/23/25, 12:53

    fyi/ there is a `stdWrap.dataWrap` which modf. the data ; USE representation-attribues @ SVG export -> CLOSE’d

  7. Garvin Hicking commented and changed status Needs Feedback Closed 05/23/25, 13:05

    great thx clsng