mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Fixed #18675 -- Fixed was_modified_since with floating-point mtime
Thanks Simon Charette for the patch.
This commit is contained in:
		| @@ -138,7 +138,7 @@ def was_modified_since(header=None, mtime=0, size=0): | |||||||
|         header_len = matches.group(3) |         header_len = matches.group(3) | ||||||
|         if header_len and int(header_len) != size: |         if header_len and int(header_len) != size: | ||||||
|             raise ValueError |             raise ValueError | ||||||
|         if mtime > header_mtime: |         if int(mtime) > header_mtime: | ||||||
|             raise ValueError |             raise ValueError | ||||||
|     except (AttributeError, ValueError, OverflowError): |     except (AttributeError, ValueError, OverflowError): | ||||||
|         return True |         return True | ||||||
|   | |||||||
| @@ -7,4 +7,4 @@ from .defaults import DefaultsTests | |||||||
| from .i18n import JsI18NTests, I18NTests, JsI18NTestsMultiPackage | from .i18n import JsI18NTests, I18NTests, JsI18NTestsMultiPackage | ||||||
| from .shortcuts import ShortcutTests | from .shortcuts import ShortcutTests | ||||||
| from .specials import URLHandling | from .specials import URLHandling | ||||||
| from .static import StaticHelperTest, StaticTests | from .static import StaticHelperTest, StaticUtilsTests, StaticTests | ||||||
|   | |||||||
| @@ -2,11 +2,14 @@ from __future__ import absolute_import | |||||||
|  |  | ||||||
| import mimetypes | import mimetypes | ||||||
| from os import path | from os import path | ||||||
|  | import unittest | ||||||
|  |  | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
| from django.conf.urls.static import static | from django.conf.urls.static import static | ||||||
| from django.test import TestCase |  | ||||||
| from django.http import HttpResponseNotModified | 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 .. import urls | ||||||
| from ..urls import media_dir | from ..urls import media_dir | ||||||
| @@ -105,3 +108,14 @@ class StaticHelperTest(StaticTests): | |||||||
|     def tearDown(self): |     def tearDown(self): | ||||||
|         super(StaticHelperTest, self).tearDown() |         super(StaticHelperTest, self).tearDown() | ||||||
|         urls.urlpatterns = self._old_views_urlpatterns |         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)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user