Issue Bug Closed

#85777<f:spaceless> eats too many blank spaces

Xavier Perseguers 08/08/18, 09:13 updated 11/07/18, 08:10

Description

My controller assign some HTML content to my view:

$foo = <<<HTML
<span class="adr">
                        <span class="type" style="display:none">work</span><span class="street-address">CP 184</span><br />
<span class="postal-code">1580</span> <span class="locality">Avenches</span> <span class="country-name" style="display:none">Switzerland</span>
                    </span>
HTML;

$this->view->assign('foo', $foo);

When the view shows the content straight, foo gets htmlentities’d but it works, however when content is raw-formatted:

{foo -> f:format.raw()}

then blank spaces between tags are eaten and result in this being outputted:

<span class="adr"><span class="type" style="display:none">work</span><span class="street-address">CP 184</span><br />
<span class="postal-code">1580</span><span class="locality">Avenches</span><span class="country-name" style="display:none">Switzerland</span></span>

(I added a break line after <br /> so that we see it more easily in this description.

Problem is that now in that particular example we have the postal code and the locality being shown visually together: 1580Avenches instead of 1580 Avenches.

This seems to be new since TYPO3 v8, same code works fine in TYPO3 v7.

Reviews 0

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

History 10

  1. Xavier Perseguers commented 08/08/18, 12:31

    Seems not to be related to <f:format.raw>, when I write this in my template:

    <p>
        <span>foo</span>
        <span>bar</span>
    </p>

    it gets rendered as

    <p><span>foo</span><span>bar</span></p>
  2. Xavier Perseguers commented and changed status New Accepted 08/08/18, 12:54

    My template does not define any layout, so the default one from EXT:fluid_styled_content is being used and this one (EXT:fluid_styled_content/Resources/Private/Layouts/Default.html) is using <f:spaceless> around the whole block.

    So it looks like <f:spaceless> just does too much space removal.

  3. Xavier Perseguers commented 08/08/18, 12:59

    This is discussed here: https://github.com/TYPO3/Fluid/issues/298

    And the sole solution at the moment is to override the default layout provided by EXT:fluid_styled_content in your own template extension :/

  4. Xavier Perseguers commented 08/08/18, 13:12

    Since I consider this a “bug” in f:spaceless which should imho not remove so many blank spaces, I personally fix it like that instead for my project:

    file <project-root>/patches/typo3fluid-fluid-298-keep-one-space.patch

    --- src/ViewHelpers/SpacelessViewHelper.php    2018-08-08 13:02:23.000000000 +0200
    +++ src/ViewHelpers/SpacelessViewHelper.php    2018-08-08 13:02:31.000000000 +0200
    @@ -52,6 +52,6 @@
          */
         public static function renderStatic(array $arguments, \Closure $childClosure, RenderingContextInterface $renderingContext)
         {
    -        return trim(preg_replace('/\\>\\s+\\</', '><', $childClosure()));
    +        return trim(preg_replace('/\\>\\s+\\</', '> <', $childClosure()));
         }
     }

    file <project-root>/composer.json

      "require": {
        "cweagans/composer-patches": "^1.6",
        // snip
      },
      "extra": {
         // snip
        "patches": {
          "typo3fluid/fluid": {
            "Keep one space between tags in f:spaceless": "patches/typo3fluid-fluid-298-keep-one-space.patch"
          }
        }
      },
  5. Xavier Perseguers changed subject <f:format.raw> eats blank spaces between tags <f:spaceless> eats too many blank spaces 08/08/18, 13:18

  6. Tymoteusz Motylewski commented 08/14/18, 15:06

    please also see this thread https://github.com/TYPO3/Fluid/issues/154

  7. Markus Klein changed Related to #86862 11/07/18, 08:08

  8. Markus Klein changed Related to #86862 11/07/18, 08:09

  9. Markus Klein changed Duplicates #86862 11/07/18, 08:09

  10. Markus Klein commented and changed status Accepted Closed 11/07/18, 08:10

    Even though this issue was there first I close it as duplicate of the newer issue where a patch is pending.