This is happening on every page load:

    public function setDefaultStrategy($defaultStrategy)
        // for BC
        if (true === $defaultStrategy) {
            @trigger_error('Using "true" as the default strategy is deprecated. Use "html" instead.', E_USER_DEPRECATED);

Proposed resolution

Use 'html'

Remaining tasks

Review patch

User interface changes


API changes


Data model changes


Beta evaluation

Major bug because we are going into the error handler for a deprecation notice on every request

#3 interdiff.txt1008 bytesCottser
#3 twig_autoescape_default-2567139-3.patch1.56 KBCottser
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 112,594 pass(es). View
twig-autoescape-html.patch593 bytesstefan.r
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 111,893 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


stefan.r created an issue. See original summary.

joelpittet’s picture

Status: Needs review » Needs work

+1 to this. Twig's default is this as well so makes sense to change this.

class Twig_Environment {
    public function __construct(Twig_LoaderInterface $loader = null, $options = array())
        $options = array_merge(array(
            'autoescape' => 'html',
        ), $options);

Can we ensure that TwigExtension::escapeFilter()'s last parameter is also using this?

and TwigExtensionTest::testEscaping() and TwigExtensionTest::testSafeStringEscaping()

Cottser’s picture

Status: Needs work » Needs review
Issue tags: +Twig
Parent issue: » #2555243: Upgrade path / plan to Twig 2.x aka 2.0
1.56 KB
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 112,594 pass(es). View
1008 bytes

Thanks for this @stefan.r, I found this too as part of #2555243: Upgrade path / plan to Twig 2.x aka 2.0.

Here's the other ones @joelpittet mentioned. I think escapeFilter() is different isn't it? It's not $strategy, the docs say:

* @param bool $autoescape
* Whether the function is called by the auto-escaping feature (TRUE) or by
* the developer (FALSE).

Which is the same as what the upstream docs say plus/minus some capitalization ;)

Leaving that one alone for now.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

You're right @Cottser ignore ::escapeFilter(), the strategy is got elsewhere.

This is a nice fix to keep this in sync with upstream and prevent setDefaultStrategy from triggering the deprecation notice.

xjm’s picture

Status: Reviewed & tested by the community » Fixed

Nice find. Committed and pushed to 8.0.x. Thanks!

  • xjm committed 86bc1ce on 8.0.x
    Issue #2567139 by Cottser, stefan.r, joelpittet: Twig autoescape default...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.