* 1.x:
fixed website URL
Fix cache update after uploading the template file (when auto-update is enabled).
Small optimization for Twig_NodeTraverser::traverseForVisitor
Add JSON escape strategy
This PR was submitted for the 2.x branch but it was merged into the 1.x branch instead (closes#2670).
Discussion
----------
Fix partial template caching after update when auto_reload is on
**Description of the bug:**
This bug manifests itself on production servers.
And with a high load the probability of getting on this bug tends to 100%
The bug results in the caching of a partial template and the failure of a part of the site working with this template. Can only be corrected by deleting the cache.
**What's happening:**
If in the process of uploading the template file, a render() is called, the partially uploaded file gets into the cache and after the template file is fully uploaded, the cache is not updated anymore.
**How to demonstrate:**
To demonstrate the bug, you can create 2 files:
File simulating the download of a file to the server (twig_test_write.php):
```
$classTwig = new Twig_Environment( new Twig_Loader_Filesystem(__DIR__."/../../site_templates/"), array(
'cache' => __DIR__.'/../../site_templates_cache',
'auto_reload'=>true
));
file_put_contents(__DIR__."/../../site_templates/"."test.twig","\n<br>Template start write to filesystem");
echo $classTwig->render("test.twig", array());
file_put_contents(__DIR__."/../../site_templates/"."test.twig"," - Template end write to filesystem",FILE_APPEND);
```
File for template rendering (twig_test_read.php):
```
$classTwig = new Twig_Environment( new Twig_Loader_Filesystem(__DIR__."/../../site_templates/"), array(
'cache' => __DIR__.'/../../site_templates_cache',
'auto_reload'=>true
));
echo $classTwig->render("test.twig", array());
```
Result executeing file twig_test_write.php:
```
Template start write to filesystem
```
Result executeing file twig_test_read.php:
```
Template start write to filesystem
```
**After this fix:**
Result executeing file twig_test_read.php:
```
Template start write to filesystem - Template end write to filesystem
```
Commits
-------
50d990e2 Fix cache update after uploading the template file (when auto-update is enabled).
If in the process of uploading the template file, a render() is called, the partially uploaded file gets into the cache and after the template file is fully uploaded, the cache is not updated anymore.
This PR was merged into the 2.x branch.
Discussion
----------
Fix links to repository in documentation
Commits
-------
e691f2a5 Fix links to repository in documentation
This PR was merged into the 2.x branch.
Discussion
----------
Reword installation docs
One must use Composer with Twig 2.x.
Commits
-------
ff9070f6 reworded installation docs
This PR was merged into the 1.x branch.
Discussion
----------
Small optimization for Twig_NodeTraverser::traverseForVisitor
During traversing a node tree `Twig_NodeTraverser::traverseForVisitor` (`Twig_NodeVisitorInterface::leaveNode`) often returns a same child node (a same object). So, there is no need to set it back to its parent.
This PR adds a check if a child node was changed. With this check a lot of calls to `Twig_Node::setNode` will be skipped.
Closes#2665
Commits
-------
555d01f3 Small optimization for Twig_NodeTraverser::traverseForVisitor
This PR was squashed before being merged into the 1.x branch (closes#2581).
Discussion
----------
Add JSON escape strategy
The `js` escape strategy used `\xNN`-style escape sequences. This is not allowed in JSON, only `\uNNNN` is allowed.
This PR adds a new escape strategy, `json` that is similar to `js` except that it does not use `\xNN` but uses `\uNNNN` instead.
I know that I can use `json_decode()`, but it came as a surprise to me that `escape('js')` did not work. You probably shouldn't be generating JSON structures in your templates, but sometimes it comes in handy. My use-case was generating a piece of [JSON-LD](https://json-ld.org).
A different approach that would perhaps be less confusing to users would be to change `js` to not use `\xNN`. This output is still valid JavaScript, it just uses two more bytes per occurrence. Let me know what you think.
Commits
-------
5c7b080b Add JSON escape strategy
This PR was merged into the 1.x branch.
Discussion
----------
Remove dev deps in composer.json
Commits
-------
64349bcf removed dev deps in composer.json
This PR was merged into the 1.x branch.
Discussion
----------
[v1] Fixed counting children of SimpleXMLElement object
It works correctly in v1.32 and since v1.33 it is not working correctly.
See: https://github.com/twigphp/Twig/compare/v1.32.0...v1.33.0#diff-d7378002f67a61c458c1de0468eef74fR1265
Test code:
```php
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><doc><elem/><elem/></doc>');
var_dump($xml instanceof \Countable);
echo 'Count: ' . count($xml), PHP_EOL;
echo 'Strlen: ' . strlen($xml), PHP_EOL;
echo 'MB Strlen: ' . mb_strlen($xml), PHP_EOL;
```
Results:
```
bool(false)
Count: 2
Strlen: 0
MB Strlen: 0
```
https://3v4l.org/VvUXG
Commits
-------
4a23bdc3 Fixed counting children of SimpleXMLElement object
* 1.x:
added missing else clause to avoid infinite loops
fixed .. (range operator) in sandbox policy
fixed version
bumped version to 1.35.3-DEV
prepared the 1.35.2 release
This PR was merged into the 1.x branch.
Discussion
----------
Add missing else clause to avoid infinite loops
Commits
-------
de2be6a0 added missing else clause to avoid infinite loops
This PR was merged into the 1.x branch.
Discussion
----------
Fix .. (range operator) in sandbox policy
Closes#2630
Commits
-------
6f45fcf5 fixed .. (range operator) in sandbox policy
This PR was merged into the 2.x branch.
Discussion
----------
Optimize parser
Depending on the complexity of the template, I see up to 50% faster template compilation.
Commits
-------
510e5eba optimized the parser by inlining the constant values
This PR was merged into the 2.x branch.
Discussion
----------
Make a small performance improvement
And it also fixes some potential subtle bugs.
Commits
-------
27f905ed made a small performance improvement