mirror of
https://github.com/django/django.git
synced 2025-02-08 08:26:13 +00:00
Fixed #31942 -- Made settings cleansing work with dictionary settings with non-string keys.
This commit is contained in:
parent
b9be11d442
commit
9c92924cd5
@ -91,18 +91,19 @@ class SafeExceptionReporterFilter:
|
|||||||
value is a dictionary, recursively cleanse the keys in that dictionary.
|
value is a dictionary, recursively cleanse the keys in that dictionary.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if self.hidden_settings.search(key):
|
is_sensitive = self.hidden_settings.search(key)
|
||||||
cleansed = self.cleansed_substitute
|
|
||||||
elif isinstance(value, dict):
|
|
||||||
cleansed = {k: self.cleanse_setting(k, v) for k, v in value.items()}
|
|
||||||
elif isinstance(value, list):
|
|
||||||
cleansed = [self.cleanse_setting('', v) for v in value]
|
|
||||||
elif isinstance(value, tuple):
|
|
||||||
cleansed = tuple([self.cleanse_setting('', v) for v in value])
|
|
||||||
else:
|
|
||||||
cleansed = value
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# If the key isn't regex-able, just return as-is.
|
is_sensitive = False
|
||||||
|
|
||||||
|
if is_sensitive:
|
||||||
|
cleansed = self.cleansed_substitute
|
||||||
|
elif isinstance(value, dict):
|
||||||
|
cleansed = {k: self.cleanse_setting(k, v) for k, v in value.items()}
|
||||||
|
elif isinstance(value, list):
|
||||||
|
cleansed = [self.cleanse_setting('', v) for v in value]
|
||||||
|
elif isinstance(value, tuple):
|
||||||
|
cleansed = tuple([self.cleanse_setting('', v) for v in value])
|
||||||
|
else:
|
||||||
cleansed = value
|
cleansed = value
|
||||||
|
|
||||||
if callable(cleansed):
|
if callable(cleansed):
|
||||||
|
@ -1274,6 +1274,19 @@ class ExceptionReporterFilterTests(ExceptionReportTestMixin, LoggingCaptureMixin
|
|||||||
{'login': 'cooper', 'password': reporter_filter.cleansed_substitute},
|
{'login': 'cooper', 'password': reporter_filter.cleansed_substitute},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_cleanse_setting_recurses_in_dictionary_with_non_string_key(self):
|
||||||
|
reporter_filter = SafeExceptionReporterFilter()
|
||||||
|
initial = {('localhost', 8000): {'login': 'cooper', 'password': 'secret'}}
|
||||||
|
self.assertEqual(
|
||||||
|
reporter_filter.cleanse_setting('SETTING_NAME', initial),
|
||||||
|
{
|
||||||
|
('localhost', 8000): {
|
||||||
|
'login': 'cooper',
|
||||||
|
'password': reporter_filter.cleansed_substitute,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
def test_cleanse_setting_recurses_in_list_tuples(self):
|
def test_cleanse_setting_recurses_in_list_tuples(self):
|
||||||
reporter_filter = SafeExceptionReporterFilter()
|
reporter_filter = SafeExceptionReporterFilter()
|
||||||
initial = [
|
initial = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user