Permalink
Browse files

merged branch duo-criativa/master (PR #544)

Commits
-------

11b8689 Refactoring: using && instead of nested if's
7aa6757 Bug correction: Parsing integers large than PHP_INT_MAX was generating trucated token values.
046e4ff Bug correction: Parsing integers large than PHP_INT_MAX was generating trucated token values.

Discussion
----------

Fixed bug that was trucating integers large then PHP_INT_MAX

The following code

{% set sizes = [7077888, 452984832, 28991029248, 1855425871872, 9223372036854775807] %}
{% for i in sizes %}
   {{ i }}
{% endfor %}

was generating the following output

7077888
452984832
2147483647
2147483647
2147483647

With the fix, the output looks like the following on Ubuntu 11.04

7077888
452984832
28991029248
1855425871872
9.2233720368548E+18
  • Loading branch information...
2 parents 6e3a1c4 + 11b8689 commit f1e5278aeab8c6522e47b893a7e5e39d7212f9cb @fabpot committed Dec 6, 2011
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/Twig/Lexer.php
View
@@ -221,7 +221,11 @@ protected function lexExpression()
}
// numbers
elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, null, $this->cursor)) {
- $this->pushToken(Twig_Token::NUMBER_TYPE, ctype_digit($match[0]) ? (int) $match[0] : (float) $match[0]);
+ $number = (float) $match[0]; // floats
+ if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) {
+ $number = (int) $match[0]; // integers lower than the maximum
+ }
+ $this->pushToken(Twig_Token::NUMBER_TYPE, $number);
$this->moveCursor($match[0]);
}
// punctuation

0 comments on commit f1e5278

Please sign in to comment.