diff options
| author | Henry Dang <henrydangprg@gmail.com> | 2016-11-26 13:23:03 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-11-29 16:12:24 -0500 |
| commit | 7cddd8a02e60332c0d02f565c450b0eea0d88438 (patch) | |
| tree | 26c56407b91b81d8a61027ff381f024324af4931 /django | |
| parent | b8a815e9dfea89034ede7ff786551f89af84a31b (diff) | |
Fixed #27358 -- Added a system check to prevent FileField's upload_to from starting with a slash.
Thanks Frank Bijlsma for the initial patch.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/fields/files.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index e3497f2494..53a31c3ed6 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -240,6 +240,7 @@ class FileField(Field): def check(self, **kwargs): errors = super(FileField, self).check(**kwargs) errors.extend(self._check_primary_key()) + errors.extend(self._check_upload_to()) return errors def _check_primary_key(self): @@ -254,6 +255,20 @@ class FileField(Field): else: return [] + def _check_upload_to(self): + if isinstance(self.upload_to, six.string_types) and self.upload_to[0] == '/': + return [ + checks.Error( + "%s's 'upload_to' argument must be a relative path, not an " + "absolute path." % self.__class__.__name__, + obj=self, + id='fields.E202', + hint='Remove the leading slash.', + ) + ] + else: + return [] + def deconstruct(self): name, path, args, kwargs = super(FileField, self).deconstruct() if kwargs.get("max_length") == 100: |
