Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "zero width spaces" and Twigified titles in backend. #1893

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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