Browse code

Merge branch '1.x' into 2.x

* 1.x:
fixed various small bugs
bumped version to 1.39.1-DEV
prepared the 1.39.0 release

Fabien Potencier authored on 16/04/2019 15:41:34
Showing 7 changed files
... ...
@@ -204,7 +204,11 @@
204 204
  * improved the performance of the filesystem loader
205 205
  * removed features that were deprecated in 1.x
206 206
 
207
-* 1.39.0 (2019-XX-XX)
207
+* 1.39.1 (2019-XX-XX)
208
+
209
+ * n/a
210
+
211
+* 1.39.0 (2019-04-16)
208 212
 
209 213
  * added Traversable support for the length filter
210 214
  * fixed some wrong location in error messages
... ...
@@ -402,6 +402,7 @@ class Environment
402 402
                 $this->cache->load($key);
403 403
             }
404 404
 
405
+            $source = null;
405 406
             if (!class_exists($cls, false)) {
406 407
                 $source = $this->getLoader()->getSourceContext($name);
407 408
                 $content = $this->compileSource($source);
... ...
@@ -1483,7 +1483,7 @@ function twig_constant_is_defined($constant, $object = null)
1483 1483
 function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
1484 1484
 {
1485 1485
     if (!twig_test_iterable($items)) {
1486
-        throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($from) ? \get_class($from) : \gettype($from)));
1486
+        throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items)));
1487 1487
     }
1488 1488
 
1489 1489
     $size = ceil($size);
... ...
@@ -27,7 +27,7 @@ class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader
27 27
 
28 28
 namespace {
29 29
 use Twig\Environment;
30
-use Twig\Template;
30
+use Twig\TemplateWrapper;
31 31
 
32 32
 /**
33 33
  * Loads a template from a string.
... ...
@@ -37,7 +37,7 @@ use Twig\Template;
37 37
  * @param string $template A template as a string or object implementing __toString()
38 38
  * @param string $name An optional name of the template to be used in error messages
39 39
  *
40
- * @return Template
40
+ * @return TemplateWrapper
41 41
  */
42 42
 function twig_template_from_string(Environment $env, $template, string $name = null)
43 43
 {
... ...
@@ -248,11 +248,11 @@ class Lexer
248 248
 
249 249
             case $this->options['tag_block'][0]:
250 250
                 // raw data?
251
-                if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, null, $this->cursor)) {
251
+                if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, 0, $this->cursor)) {
252 252
                     $this->moveCursor($match[0]);
253 253
                     $this->lexRawData();
254 254
                 // {% line \d+ %}
255
-                } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, null, $this->cursor)) {
255
+                } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, 0, $this->cursor)) {
256 256
                     $this->moveCursor($match[0]);
257 257
                     $this->lineno = (int) $match[1];
258 258
                 } else {
... ...
@@ -272,7 +272,7 @@ class Lexer
272 272
 
273 273
     private function lexBlock()
274 274
     {
275
-        if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) {
275
+        if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) {
276 276
             $this->pushToken(/* Token::BLOCK_END_TYPE */ 3);
277 277
             $this->moveCursor($match[0]);
278 278
             $this->popState();
... ...
@@ -283,7 +283,7 @@ class Lexer
283 283
 
284 284
     private function lexVar()
285 285
     {
286
-        if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) {
286
+        if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) {
287 287
             $this->pushToken(/* Token::VAR_END_TYPE */ 4);
288 288
             $this->moveCursor($match[0]);
289 289
             $this->popState();
... ...
@@ -295,7 +295,7 @@ class Lexer
295 295
     private function lexExpression()
296 296
     {
297 297
         // whitespace
298
-        if (preg_match('/\s+/A', $this->code, $match, null, $this->cursor)) {
298
+        if (preg_match('/\s+/A', $this->code, $match, 0, $this->cursor)) {
299 299
             $this->moveCursor($match[0]);
300 300
 
301 301
             if ($this->cursor >= $this->end) {
... ...
@@ -304,17 +304,17 @@ class Lexer
304 304
         }
305 305
 
306 306
         // operators
307
-        if (preg_match($this->regexes['operator'], $this->code, $match, null, $this->cursor)) {
307
+        if (preg_match($this->regexes['operator'], $this->code, $match, 0, $this->cursor)) {
308 308
             $this->pushToken(/* Token::OPERATOR_TYPE */ 8, preg_replace('/\s+/', ' ', $match[0]));
309 309
             $this->moveCursor($match[0]);
310 310
         }
311 311
         // names
312
-        elseif (preg_match(self::REGEX_NAME, $this->code, $match, null, $this->cursor)) {
312
+        elseif (preg_match(self::REGEX_NAME, $this->code, $match, 0, $this->cursor)) {
313 313
             $this->pushToken(/* Token::NAME_TYPE */ 5, $match[0]);
314 314
             $this->moveCursor($match[0]);
315 315
         }
316 316
         // numbers
317
-        elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, null, $this->cursor)) {
317
+        elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) {
318 318
             $number = (float) $match[0];  // floats
319 319
             if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) {
320 320
                 $number = (int) $match[0]; // integers lower than the maximum
... ...
@@ -344,12 +344,12 @@ class Lexer
344 344
             ++$this->cursor;
345 345
         }
346 346
         // strings
347
-        elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) {
347
+        elseif (preg_match(self::REGEX_STRING, $this->code, $match, 0, $this->cursor)) {
348 348
             $this->pushToken(/* Token::STRING_TYPE */ 7, stripcslashes(substr($match[0], 1, -1)));
349 349
             $this->moveCursor($match[0]);
350 350
         }
351 351
         // opening double quoted string
352
-        elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
352
+        elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
353 353
             $this->brackets[] = ['"', $this->lineno];
354 354
             $this->pushState(self::STATE_STRING);
355 355
             $this->moveCursor($match[0]);
... ...
@@ -395,15 +395,15 @@ class Lexer
395 395
 
396 396
     private function lexString()
397 397
     {
398
-        if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) {
398
+        if (preg_match($this->regexes['interpolation_start'], $this->code, $match, 0, $this->cursor)) {
399 399
             $this->brackets[] = [$this->options['interpolation'][0], $this->lineno];
400 400
             $this->pushToken(/* Token::INTERPOLATION_START_TYPE */ 10);
401 401
             $this->moveCursor($match[0]);
402 402
             $this->pushState(self::STATE_INTERPOLATION);
403
-        } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, null, $this->cursor) && \strlen($match[0]) > 0) {
403
+        } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) {
404 404
             $this->pushToken(/* Token::STRING_TYPE */ 7, stripcslashes($match[0]));
405 405
             $this->moveCursor($match[0]);
406
-        } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
406
+        } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
407 407
             list($expect, $lineno) = array_pop($this->brackets);
408 408
             if ('"' != $this->code[$this->cursor]) {
409 409
                 throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
... ...
@@ -420,7 +420,7 @@ class Lexer
420 420
     private function lexInterpolation()
421 421
     {
422 422
         $bracket = end($this->brackets);
423
-        if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, null, $this->cursor)) {
423
+        if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, 0, $this->cursor)) {
424 424
             array_pop($this->brackets);
425 425
             $this->pushToken(/* Token::INTERPOLATION_END_TYPE */ 11);
426 426
             $this->moveCursor($match[0]);
... ...
@@ -206,7 +206,7 @@ abstract class IntegrationTestCase extends TestCase
206 206
                     $message = $e->getMessage();
207 207
                     $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $message)));
208 208
                     $last = substr($message, \strlen($message) - 1);
209
-                    $this->assertTrue('.' === $last || '?' === $last, $message, 'Exception message must end with a dot or a question mark.');
209
+                    $this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.');
210 210
 
211 211
                     return;
212 212
                 }
... ...
@@ -55,7 +55,7 @@ abstract class NodeTestCase extends TestCase
55 55
     {
56 56
         $line = $line > 0 ? "// line {$line}\n" : '';
57 57
 
58
-        return sprintf('%s($context["%s"] ?? null)', $line, $name, $name);
58
+        return sprintf('%s($context["%s"] ?? null)', $line, $name);
59 59
     }
60 60
 
61 61
     protected function getAttributeGetter()