diff --git a/axes/helpers.py b/axes/helpers.py index e633821..1adb7e4 100644 --- a/axes/helpers.py +++ b/axes/helpers.py @@ -230,15 +230,10 @@ def get_client_str( path_info = path_info[0] client_dict["path_info"] = path_info - # Template the internal dictionary representation into a readable and concatenated key: "value" format + # Template the internal dictionary representation into a readable and concatenated {key: "value"} format template = ", ".join(f'{key}: "{value}"' for key, value in client_dict.items()) - - # Wrap the internal dict into a single {key: "value"} bracing in the output - # which requires double braces when done with the Python string templating system - # i.e. {{key: "value"}} becomes {key: "value"} when run through a .format() call - template = "{{" + template + "}}" - - return template.format(client_dict) + template = "{" + template + "}" + return template def get_query_str(query: Type[QueryDict], max_length: int = 1024) -> str: diff --git a/axes/tests/test_utils.py b/axes/tests/test_utils.py index 2d6f13a..2500d80 100644 --- a/axes/tests/test_utils.py +++ b/axes/tests/test_utils.py @@ -97,6 +97,20 @@ class ClientStringTestCase(AxesTestCase): self.assertEqual(expected, actual) + @override_settings(AXES_VERBOSE=True) + def test_imbalanced_quotes(self): + username = "butterfly.. },,," + ip_address = "127.0.0.1" + user_agent = "Googlebot/2.1 (+http://www.googlebot.com/bot.html)" + path_info = "/admin/" + + expected = self.get_expected_client_str( + username, ip_address, user_agent, path_info + ) + actual = get_client_str(username, ip_address, user_agent, path_info) + + self.assertEqual(expected, actual) + @override_settings(AXES_VERBOSE=True) def test_verbose_ip_only_client_details_tuple(self): username = "test@example.com"