Ticket #21080: 21080-pyparsing.patch

File 21080-pyparsing.patch, 3.3 KB (added by Claude Paroz, 21 months ago)
  • django/contrib/staticfiles/storage.py

    diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
    index 445cf6b954..91c2dab87e 100644
    a b import posixpath  
    44import re
    55from urllib.parse import unquote, urldefrag, urlsplit, urlunsplit
    66
     7import pyparsing
     8
    79from django.conf import STATICFILES_STORAGE_ALIAS, settings
    810from django.contrib.staticfiles.utils import check_settings, matches_patterns
    911from django.core.exceptions import ImproperlyConfigured
    class HashedFilesMixin:  
    103105        super().__init__(*args, **kwargs)
    104106        self._patterns = {}
    105107        self.hashed_files = {}
     108        self.comment_remover = pyparsing.cpp_style_comment.suppress()
    106109        for extension, patterns in self.patterns:
    107110            for pattern in patterns:
    108111                if isinstance(pattern, (tuple, list)):
    class HashedFilesMixin:  
    363366                                try:
    364367                                    content = pattern.sub(converter, content)
    365368                                except ValueError as exc:
    366                                     yield name, None, exc, False
     369                                    # Try a second time with comments removed.
     370                                    content = self.comment_remover.transform_string(content)
     371                                    try:
     372                                        content = pattern.sub(converter, content)
     373                                    except ValueError as exc:
     374                                        yield name, None, exc, False
    367375                    if hashed_file_exists:
    368376                        self.delete(hashed_name)
    369377                    # then save the processed result
  • tests/staticfiles_tests/project/documents/cached/module.js

    diff --git a/tests/staticfiles_tests/project/documents/cached/module.js b/tests/staticfiles_tests/project/documents/cached/module.js
    index 7764e740d6..61def68e9b 100644
    a b export {  
    2020    firstVar as firstVarAlias,
    2121    secondVar as secondVarAlias
    2222} from "./module_test.js";
     23
     24// Imports inside comments should be ignored.
     25/**
     26 * @param {HTMLElement} elt
     27 * @returns {import("./htmx").HtmxTriggerSpecification[]}
     28 */
  • tests/staticfiles_tests/test_storage.py

    diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
    index 11b160945e..482ee3b5a3 100644
    a b class TestHashedFiles:  
    179179
    180180    def test_module_import(self):
    181181        relpath = self.hashed_file_path("cached/module.js")
    182         self.assertEqual(relpath, "cached/module.55fd6938fbc5.js")
     182        self.assertEqual(relpath, "cached/module.7b546b090392.js")
    183183        tests = [
    184184            # Relative imports.
    185185            b'import testConst from "./module_test.477bbebe77f0.js";',
    class TestHashedFiles:  
    207207
    208208    def test_aggregating_modules(self):
    209209        relpath = self.hashed_file_path("cached/module.js")
    210         self.assertEqual(relpath, "cached/module.55fd6938fbc5.js")
     210        self.assertEqual(relpath, "cached/module.7b546b090392.js")
    211211        tests = [
    212212            b'export * from "./module_test.477bbebe77f0.js";',
    213213            b'export { testConst } from "./module_test.477bbebe77f0.js";',
Back to Top