0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Fixed #18675 -- Fixed was_modified_since with floating-point mtime

Thanks Simon Charette for the patch.
This commit is contained in:
Claude Paroz 2012-09-26 21:12:56 +02:00
parent b3ee80a0cf
commit 3cbe686af6
3 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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))