Hello everyone,
I’d like to contribute to ticket #32849 (“ManifestStaticFilesStorage line breaks regex”) and would appreciate feedback before submitting a patch. Here’s my analysis:
Current Behavior
- Files are loaded with original line breaks (storage.py#L315)
- Default regex patterns (like
url()
) work because minifiers preserve them - Custom regex patterns (like CKEditor’s
appendStyleSheet
) fail when line breaks exist
Proposed Solutions
Option 1: Pre-process content (remove line breaks)
def read_manifest(self):
content = super().read_manifest()
return content.replace('\n', '') # Simple but might break sourcemaps?
Option 2 : Document the requirement for line break-aware regex
# In docs:
"Custom patterns must account for potential line breaks, e.g. r'\s?' between tokens"
Option 3 : Auto-convert patterns
def prepare_pattern(self, pattern):
return pattern.replace(' ', '\s*') # Automatic whitespace handling
Questions
- Which approach aligns best with Django’s philosophy?
- Should this be considered a bug fix (Option 1) or a docs clarification (Option 2)?
- Are there edge cases I’m missing? (e.g., sourcemaps, CSS comments)
Geordan