diff --git a/django/views/static.py b/django/views/static.py index 2ff22ce13f..7dd44c5772 100644 --- a/django/views/static.py +++ b/django/views/static.py @@ -138,7 +138,7 @@ def was_modified_since(header=None, mtime=0, size=0): header_len = matches.group(3) if header_len and int(header_len) != size: raise ValueError - if mtime > header_mtime: + if int(mtime) > header_mtime: raise ValueError except (AttributeError, ValueError, OverflowError): return True diff --git a/tests/regressiontests/views/tests/__init__.py b/tests/regressiontests/views/tests/__init__.py index 63db5da2a3..12d0c59014 100644 --- a/tests/regressiontests/views/tests/__init__.py +++ b/tests/regressiontests/views/tests/__init__.py @@ -7,4 +7,4 @@ from .defaults import DefaultsTests from .i18n import JsI18NTests, I18NTests, JsI18NTestsMultiPackage from .shortcuts import ShortcutTests from .specials import URLHandling -from .static import StaticHelperTest, StaticTests +from .static import StaticHelperTest, StaticUtilsTests, StaticTests diff --git a/tests/regressiontests/views/tests/static.py b/tests/regressiontests/views/tests/static.py index 9d87ade137..38cf38ce46 100644 --- a/tests/regressiontests/views/tests/static.py +++ b/tests/regressiontests/views/tests/static.py @@ -2,11 +2,14 @@ from __future__ import absolute_import import mimetypes from os import path +import unittest from django.conf import settings from django.conf.urls.static import static -from django.test import TestCase from django.http import HttpResponseNotModified +from django.test import TestCase +from django.utils.http import http_date +from django.views.static import was_modified_since from .. import urls from ..urls import media_dir @@ -105,3 +108,14 @@ class StaticHelperTest(StaticTests): def tearDown(self): super(StaticHelperTest, self).tearDown() urls.urlpatterns = self._old_views_urlpatterns + + +class StaticUtilsTests(unittest.TestCase): + def test_was_modified_since_fp(self): + """ + Test that a floating point mtime does not disturb was_modified_since. + (#18675) + """ + mtime = 1343416141.107817 + header = http_date(mtime) + self.assertFalse(was_modified_since(header, mtime))