{"action":"created","issue":{"url":"https://api.github.com/repos/twigphp/Twig/issues/1689","labels_url":"https://api.github.com/repos/twigphp/Twig/issues/1689/labels{/name}","comments_url":"https://api.github.com/repos/twigphp/Twig/issues/1689/comments","events_url":"https://api.github.com/repos/twigphp/Twig/issues/1689/events","html_url":"https://github.com/twigphp/Twig/issues/1689","id":75625872,"number":1689,"title":"Double escaping when using custom esaper","user":{"login":"Koc","id":191082,"avatar_url":"https://avatars.githubusercontent.com/u/191082?v=3","gravatar_id":"","url":"https://api.github.com/users/Koc","html_url":"https://github.com/Koc","followers_url":"https://api.github.com/users/Koc/followers","following_url":"https://api.github.com/users/Koc/following{/other_user}","gists_url":"https://api.github.com/users/Koc/gists{/gist_id}","starred_url":"https://api.github.com/users/Koc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Koc/subscriptions","organizations_url":"https://api.github.com/users/Koc/orgs","repos_url":"https://api.github.com/users/Koc/repos","events_url":"https://api.github.com/users/Koc/events{/privacy}","received_events_url":"https://api.github.com/users/Koc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-12T14:39:51Z","updated_at":"2015-05-12T14:46:58Z","closed_at":null,"body":"I need create custom escaper which would replace `'` with `\\'` and call `html_attr` escaping for processed string.\r\n\r\n```php\r\n<?php\r\n\r\nnamespace Metal\\ProjectBundle\\Twig;\r\n\r\nclass AngularEscaping extends \\Twig_Extension\r\n{\r\n    public function initRuntime(\\Twig_Environment $environment)\r\n    {\r\n        $environment->getExtension('core')->setEscaper('angular', array($this, 'angularEscaping'));\r\n    }\r\n\r\n    public function angularEscaping(\\Twig_Environment $environment, $string, $charset)\r\n    {\r\n        $string = str_replace(\"'\", \"\\\\'\", $string);\r\n\r\n        return twig_escape_filter($environment, $string, 'html_attr', $charset);\r\n    }\r\n\r\n    public function getName()\r\n    {\r\n        return 'angular_escaping';\r\n    }\r\n}\r\n```\r\n```php\r\n`$a = \"'4\"`\r\n```\r\n```twig\r\n{{ a|replace({\"'\": \"\\\\'\"})|escape('html_attr') }}\r\n{# &#x5C;&#x27;4 - as expected #}\r\n\r\n{{ a|escape('angular') }}\r\n{# &amp;#x5C;&amp;#x27;4 - automatic html escaping goes after my custom escaper #}\r\n```"},"comment":{"url":"https://api.github.com/repos/twigphp/Twig/issues/comments/101306373","html_url":"https://github.com/twigphp/Twig/issues/1689#issuecomment-101306373","issue_url":"https://api.github.com/repos/twigphp/Twig/issues/1689","id":101306373,"user":{"login":"Koc","id":191082,"avatar_url":"https://avatars.githubusercontent.com/u/191082?v=3","gravatar_id":"","url":"https://api.github.com/users/Koc","html_url":"https://github.com/Koc","followers_url":"https://api.github.com/users/Koc/followers","following_url":"https://api.github.com/users/Koc/following{/other_user}","gists_url":"https://api.github.com/users/Koc/gists{/gist_id}","starred_url":"https://api.github.com/users/Koc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Koc/subscriptions","organizations_url":"https://api.github.com/users/Koc/orgs","repos_url":"https://api.github.com/users/Koc/repos","events_url":"https://api.github.com/users/Koc/events{/privacy}","received_events_url":"https://api.github.com/users/Koc/received_events","type":"User","site_admin":false},"created_at":"2015-05-12T14:46:58Z","updated_at":"2015-05-12T14:46:58Z","body":"As workaround I can replace escaping callable with\r\n```php\r\n    public function angularEscaping(\\Twig_Environment $environment, $string, $charset)\r\n    {\r\n        $string = str_replace(\"'\", \"\\\\'\", $string);\r\n\r\n        return new \\Twig_Markup(twig_escape_filter($environment, $string, 'html_attr', $charset), $charset);\r\n    }\r\n```\r\nbuy it looks buggy. As I see we have similar problem some time ago https://github.com/twigphp/Twig/pull/1211"}}