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 commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2025-05-23T11:56:45+00:00" > 05/23/25, 11:56 </span>

    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?

  2. Marcus Förster commented <span data-processor="relativetime" data-value="2025-05-23T12:00:59+00:00" > 05/23/25, 12:00 </span>

        stdWrap.cObject = FILES
        stdWrap.cObject {
          references {
            data = levelmedia:-1
          }
          renderObj = SVG
          renderObj {
            renderMode = inline
            src.wrap = fileadmin|
            src.data = file:current:identifier
          }
        }
  3. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-05-23T12:10:29+00:00" > 05/23/25, 12:10 </span>

    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.

  4. Marcus Förster commented <span data-processor="relativetime" data-value="2025-05-23T12:22:52+00:00" > 05/23/25, 12:22 </span>

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

  5. Marcus Förster commented <span data-processor="relativetime" data-value="2025-05-23T12:53:00+00:00" > 05/23/25, 12:53 </span>

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

  6. Garvin Hicking commented and changed status Needs Feedback Closed <span data-processor="relativetime" data-value="2025-05-23T13:05:32+00:00" > 05/23/25, 13:05 </span>

    great thx clsng