summaryrefslogtreecommitdiff
path: root/django/template/base.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2017-10-21 12:24:20 +0200
committerClaude Paroz <claude@2xlibre.net>2017-10-21 17:20:29 +0200
commit9ec7d8e514e09636b0ab4bcac74b5f7a5be335a3 (patch)
tree9da88d2c0c7ab16b88971c47aba7f61044339e5a /django/template/base.py
parent45d5d2dcaa72aa60a2ad2b8d7f0f299b8410b314 (diff)
Fixed #28730 -- Fixed loss of precision for large integer literals in templates
Thanks Fraser Nevett for the report and Tim Graham for patch edits.
Diffstat (limited to 'django/template/base.py')
-rw-r--r--django/template/base.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/django/template/base.py b/django/template/base.py
index 10a1f11464..9c81a361f2 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -762,17 +762,16 @@ class Variable:
# Note that this could cause an OverflowError here that we're not
# catching. Since this should only happen at compile time, that's
# probably OK.
- self.literal = float(var)
-
- # So it's a float... is it an int? If the original value contained a
- # dot or an "e" then it was a float, not an int.
- if '.' not in var and 'e' not in var.lower():
- self.literal = int(self.literal)
-
- # "2." is invalid
- if var.endswith('.'):
- raise ValueError
+ # Try to interpret values containg a period or an 'e'/'E'
+ # (possibly scientific notation) as a float; otherwise, try int.
+ if '.' in var or 'e' in var.lower():
+ self.literal = float(var)
+ # "2." is invalid
+ if var.endswith('.'):
+ raise ValueError
+ else:
+ self.literal = int(var)
except ValueError:
# A ValueError means that the variable isn't a number.
if var.startswith('_(') and var.endswith(')'):