10000 [AssetMapper] JavaScriptImportPathCompiler::compile(): Return value must be of type string, null returned · Issue #54078 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[AssetMapper] JavaScriptImportPathCompiler::compile(): Return value must be of type string, null returned #54078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PhilETaylor opened this issue Feb 27, 2024 · 11 comments

Comments

@PhilETaylor
Copy link
Contributor
PhilETaylor commented Feb 27, 2024

Symfony version(s) affected

6.4.4

Description

Regression in AssetMapper 6.4.4 released today

ScreenShot-2024-02-27-08 57 24

How to reproduce

symfony new . --version="6.4.*" --webapp
php bin/console importmap:req @yaireo/tagify
php bin/console importmap:update 

ScreenShot-2024-02-27-09 20 40

Possible Solution

No response

Additional Context

No response

@PhilETaylor
Copy link
Contributor Author

A quick test with a preg_match at the start of the compile method like

ScreenShot-2024-02-27-09 08 28

gives

ScreenShot-2024-02-27-09 08 00

@Chris53897
Copy link
Contributor
Chris53897 commented Feb 27, 2024

Same for Symfony 7.0.4
--env=prod asset-map:compile -q

09:14:30 CRITICAL  [console] Error thrown while running command "--env=prod asset-map:compile -q". Message: "Symfony\Component\AssetMapper\Compiler\JavaScriptImportPathCompiler::compile(): Return value must be of type string, null returned" ["exception" => TypeError { …},"command" => "--env=prod asset-map:compile -q","message" => "Symfony\Component\AssetMapper\Compiler\JavaScriptImportPathCompiler::compile(): Return value must be of type string, null returned"]

In JavaScriptImportPathCompiler.php line 119:
                                                                                                                                      
  Symfony\Component\AssetMapper\Compiler\JavaScriptImportPathCompiler::compile(): Return value must be of type string, null returned  

@smnandre Could you please check if this is related?
#53652

@fracsi
Copy link
Contributor
fracsi commented Feb 27, 2024

The preg_last_error_msg is JIT stack limit exhausted
Quick fix: disable pcre.jit in php.ini

@nicolas-grekas
Copy link
Member

Can you try this diff? Does that help?

--- a/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php
+++ b/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php
@@ -31,13 +31,12 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
      * @see https://regex101.com/r/1iBAIb/1
      */
     private const IMPORT_PATTERN = '/
-        ^
-            (?:\/\/.*)                     # Lines that start with comments
+            ^(?:\/\/.*)                     # Lines that start with comments
         |
             (?:
-                \'(?:[^\'\\\\\n]|\\\\.)*\'   # Strings enclosed in single quotes
+                \'(?:[^\'\\\\\n]|\\\\.)*+\'   # Strings enclosed in single quotes
             |
-                "(?:[^"\\\\\n]|\\\\.)*"      # Strings enclosed in double quotes
+                "(?:[^"\\\\\n]|\\\\.)*+"      # Strings enclosed in double quotes
             )
         |
             (?:                            # Import statements (script captured)
@@ -49,7 +48,7 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
             |
                 \bimport\(
             )
-            \s*[\'"`](\.\/[^\'"`\n]+|(\.\.\/)*[^\'"`\n]+)[\'"`]\s*[;\)]
+            \s*[\'"`](\.\/[^\'"`\n]++|(\.\.\/)*+[^\'"`\n]++)[\'"`]\s*[;\)]
         ?
     /mx';
 

@PhilETaylor
Copy link
Contributor Author
PhilETaylor commented Feb 27, 2024

Hey @nicolas-grekas YES! I apply (manually) your diff and now the import is correctly made with no errors.

private const IMPORT_PATTERN = '/
        ^
           ^(?:\/\/.*)                     # Lines that start with comments
        |
            (?:
                \'(?:[^\'\\\\\n]|\\\\.)*+\'   # Strings enclosed in single quotes
            |
                "(?:[^"\\\\\n]|\\\\.)*+"       # Strings enclosed in double quotes
            )
        |
            (?:                            # Import statements (script captured)
                import\s*
                    (?:
                        (?:\*\s*as\s+\w+|\s+[\w\s{},*]+)
                        \s*from\s*
                    )?
            |
                \bimport\(
            )
             \s*[\'"`](\.\/[^\'"`\n]++|(\.\.\/)*+[^\'"`\n]++)[\'"`]\s*[;\)]
        ?
    /mx';

ScreenShot-2024-02-27-09 47 56

@nicolas-grekas
Copy link
Member

Cool. Up for a PR?

@PhilETaylor
Copy link
Contributor Author

#54079

@Chris53897
Copy link
Contributor

Thanks for the Fix.
Should this Issue maybe reopened, just to Inform other users until 7.0.5 is released?

@PhilETaylor PhilETaylor reopened this Feb 27, 2024
@ThomasLandauer
Copy link
Contributor

Other quick fix: Add this to your composer.json to downgrade to 7.0.3:

"conflict": {
    "symfony/asset-mapper": "7.0.4"
},

@stof
Copy link
Member
stof commented Feb 27, 2024

@Chris53897 no. Open issues are the unresolved.

@xabbuh
Copy link
Member
xabbuh commented Feb 28, 2024

reopening as the linked PR isn't merged yet

@xabbuh xabbuh reopened this Feb 28, 2024
nicolas-grekas added a commit that referenced this issue Feb 29, 2024
…n in regex (PhilETaylor)

This PR was squashed before being merged into the 6.4 branch.

Discussion
----------

[AssetMapper] Fix `JavaScriptImportPathCompiler` regression in regex

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues        | Fix #54078
| License       | MIT

Fixes regression in regex, fix provided by `@nicolas`-grekas in #54078

Commits
-------

ae16b2d [AssetMapper] Fix `JavaScriptImportPathCompiler` regression in regex
qdequippe added a commit to jobbsy-dev/jobbsy that referenced this issue Mar 4, 2024
fabpot added a commit that referenced this issue Mar 4, 2024
…PCRE error (smnandre)

This PR was squashed before being merged into the 6.4 branch.

Discussion
----------

[AssetMapper] Throw exception in Javascript compiler when PCRE error

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #...
| License       | MIT

`preg_match_callback` can return null when a PCRE error occured, leading there to a TypeError.

Let's throw an exception and expose the error message.

(follows #54078 / complementary to #54079 )

Commits
-------

2333b58 [AssetMapper] Throw exception in Javascript compiler when PCRE error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants
0