From 98df288ddaba9787e4a370f12aba51c2b9133142 Mon Sep 17 00:00:00 2001 From: Moritz Sichert Date: Sat, 13 Jun 2015 12:20:05 +0200 Subject: Fixed #24978 -- Escaped special characters in loaddata fixture paths --- tests/fixtures/fixtures/fixture?with[special]chars*.json | 10 ++++++++++ tests/fixtures/tests.py | 4 ++++ tests/utils_tests/test_glob.py | 15 +++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/fixtures/fixtures/fixture?with[special]chars*.json create mode 100644 tests/utils_tests/test_glob.py (limited to 'tests') diff --git a/tests/fixtures/fixtures/fixture?with[special]chars*.json b/tests/fixtures/fixtures/fixture?with[special]chars*.json new file mode 100644 index 0000000000..b6b7ad2a7c --- /dev/null +++ b/tests/fixtures/fixtures/fixture?with[special]chars*.json @@ -0,0 +1,10 @@ +[ + { + "pk": "1", + "model": "fixtures.article", + "fields": { + "headline": "How To Deal With Special Characters", + "pub_date": "2006-06-16 12:00:00" + } + } +] diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 544b70473b..d87f1942ff 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -224,6 +224,10 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): "Unknown model in excludes: fixtures.FooModel"): self._dumpdata_assert(['fixtures', 'sites'], '', exclude_list=['fixtures.FooModel']) + def test_load_fixture_with_special_characters(self): + management.call_command('loaddata', 'fixture?with[special]chars*', verbosity=0) + self.assertQuerysetEqual(Article.objects.all(), ['']) + def test_dumpdata_with_filtering_manager(self): spy1 = Spy.objects.create(name='Paul') spy2 = Spy.objects.create(name='Alex', cover_blown=True) diff --git a/tests/utils_tests/test_glob.py b/tests/utils_tests/test_glob.py new file mode 100644 index 0000000000..7e72815ef8 --- /dev/null +++ b/tests/utils_tests/test_glob.py @@ -0,0 +1,15 @@ +from __future__ import unicode_literals + +from django.test import SimpleTestCase +from django.utils.glob import glob_escape + + +class TestUtilsGlob(SimpleTestCase): + def test_glob_escape(self): + filename = '/my/file?/name[with special chars*' + expected = '/my/file[?]/name[[]with special chars[*]' + filename_b = b'/my/file?/name[with special chars*' + expected_b = b'/my/file[?]/name[[]with special chars[*]' + + self.assertEqual(glob_escape(filename), expected) + self.assertEqual(glob_escape(filename_b), expected_b) -- cgit v1.3