mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #17778 -- Prevented class attributes on context from resolving as template variables.
Thanks KyleMac for the report, regebro for the patch, and Aymeric for the test.
This commit is contained in:
@@ -6,7 +6,7 @@ from importlib import import_module
|
||||
from inspect import getargspec
|
||||
|
||||
from django.conf import settings
|
||||
from django.template.context import (Context, RequestContext,
|
||||
from django.template.context import (BaseContext, Context, RequestContext,
|
||||
ContextPopException)
|
||||
from django.utils.itercompat import is_iterable
|
||||
from django.utils.text import (smart_split, unescape_string_literal,
|
||||
@@ -765,6 +765,9 @@ class Variable(object):
|
||||
current = current[bit]
|
||||
except (TypeError, AttributeError, KeyError, ValueError):
|
||||
try: # attribute lookup
|
||||
# Don't return class attributes if the class is the context:
|
||||
if isinstance(current, BaseContext) and getattr(type(current), bit):
|
||||
raise AttributeError
|
||||
current = getattr(current, bit)
|
||||
except (TypeError, AttributeError):
|
||||
try: # list-index lookup
|
||||
|
||||
Reference in New Issue
Block a user