mirror of
https://github.com/django/django.git
synced 2025-01-09 09:55:57 +00:00
Fixed #35371 -- Ensured that only unhashed file paths were being processed.
Used different functions for increased readability. Fixed edge case and added test for newlines. Used a different method for splitting the content which didn't remove the ending newline.
This commit is contained in:
parent
40bfd7b09a
commit
a231f9b08d
@ -364,7 +364,8 @@ class HashedFilesMixin:
|
||||
if name in adjustable_paths:
|
||||
old_hashed_name = hashed_name
|
||||
try:
|
||||
content = original_file.read().decode("utf-8")
|
||||
unprocessed_content = original_file.read().decode("utf-8")
|
||||
final_content = unprocessed_content
|
||||
except UnicodeDecodeError as exc:
|
||||
yield name, None, exc, False
|
||||
for extension, patterns in self._patterns.items():
|
||||
@ -374,13 +375,29 @@ class HashedFilesMixin:
|
||||
name, hashed_files, template
|
||||
)
|
||||
try:
|
||||
content = pattern.sub(converter, content)
|
||||
processed_content = pattern.sub(
|
||||
converter, unprocessed_content
|
||||
)
|
||||
final_content_lines = final_content.split("\n")
|
||||
processed_content_lines = processed_content.split(
|
||||
"\n"
|
||||
)
|
||||
for i, final_content_line in enumerate(
|
||||
final_content_lines
|
||||
):
|
||||
if len(final_content_line) < len(
|
||||
processed_content_lines[i]
|
||||
):
|
||||
final_content_lines[i] = (
|
||||
processed_content_lines[i]
|
||||
) # Keep the processed line
|
||||
final_content = "\n".join(final_content_lines)
|
||||
except ValueError as exc:
|
||||
yield name, None, exc, False
|
||||
if hashed_file_exists:
|
||||
self.delete(hashed_name)
|
||||
# then save the processed result
|
||||
content_file = ContentFile(content.encode())
|
||||
content_file = ContentFile(final_content.encode())
|
||||
if self.keep_intermediate_files:
|
||||
# Save intermediate file for reference
|
||||
self._save(hashed_name, content_file)
|
||||
|
@ -1,3 +1,21 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const moduleConst2 = "module2";
|
||||
export default moduleConst2;
|
||||
export const moduleConst = "module";
|
||||
// export keyword test
|
||||
|
||||
// Static imports.
|
||||
import rootConst from "/static/absolute_root.js";
|
||||
import testConst from "./module_test.js";
|
||||
@ -18,9 +36,24 @@ import relativeModule from "../nested/js/nested.js";
|
||||
const dynamicModule = import("./module_test.js");
|
||||
|
||||
// Modules exports to aggregate modules.
|
||||
export * from "./module_test.js";
|
||||
export * from "./module_test.js"; // export keyword test
|
||||
export { testConst } from "./module_test.js";
|
||||
export {
|
||||
firstVar as firstVarAlias,
|
||||
secondVar as secondVarAlias
|
||||
} from "./module_test.js";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -676,7 +676,7 @@ class TestCollectionJSModuleImportAggregationManifestStorage(CollectionTestCase)
|
||||
|
||||
def test_module_import(self):
|
||||
relpath = self.hashed_file_path("cached/module.js")
|
||||
self.assertEqual(relpath, "cached/module.4326210cf0bd.js")
|
||||
self.assertEqual(relpath, "cached/module.f0c3a6133ad5.js")
|
||||
tests = [
|
||||
# Relative imports.
|
||||
b'import testConst from "./module_test.477bbebe77f0.js";',
|
||||
@ -708,7 +708,7 @@ class TestCollectionJSModuleImportAggregationManifestStorage(CollectionTestCase)
|
||||
|
||||
def test_aggregating_modules(self):
|
||||
relpath = self.hashed_file_path("cached/module.js")
|
||||
self.assertEqual(relpath, "cached/module.4326210cf0bd.js")
|
||||
self.assertEqual(relpath, "cached/module.f0c3a6133ad5.js")
|
||||
tests = [
|
||||
b'export * from "./module_test.477bbebe77f0.js";',
|
||||
b'export { testConst } from "./module_test.477bbebe77f0.js";',
|
||||
|
Loading…
Reference in New Issue
Block a user