Skip to content

Commit

Permalink
Merge pull request #1893 from bolt/fix/invisible-chars-and-twigified-…
Browse files Browse the repository at this point in the history
…titles

Fix "zero width spaces" and Twigified titles in backend.
  • Loading branch information
I-Valchev authored Sep 23, 2020
2 parents f1c3e00 + 91096e5 commit f3c692c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Entity/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use Bolt\Common\Arr;
use Bolt\Configuration\Content\FieldType;
use Bolt\Widget\Injector\RequestZone;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Tightenco\Collect\Support\Collection as LaravelCollection;
Expand Down Expand Up @@ -258,7 +260,7 @@ public function getTwigValue()

private function shouldBeRenderedAsTwig($value): bool
{
return is_string($value) && $this->getDefinition()->get('allow_twig') && preg_match('/{[{%#]/', $value);
return RequestZone::isForFrontend(Request::createFromGlobals()) && is_string($value) && $this->getDefinition()->get('allow_twig') && preg_match('/{[{%#]/', $value);
}

public function set(string $key, $value): self
Expand Down
4 changes: 2 additions & 2 deletions templates/_partials/fields/_base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
{% set value = value|first %}
{% endif %}

{# We're adding zero width spaces in `{{` and `}}`, to ensure Vue doesn't get its grubby paws on it. #}
{# We're adding zero width spaces (`\xE2\x80\x8B`) in `{{` and `}}`, to ensure Vue doesn't get its grubby paws on it. #}
{% if value is string %}
{% set value = value|replace({'{{': '{​{', '}}': '}​}'}) %}
{% set value = value|replace({'{{': "{\xE2\x80\x8B{", '}}': "}\xE2\x80\x8B}" }) %}
{% endif %}
{% endif %}

Expand Down

0 comments on commit f3c692c

Please sign in to comment.