Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[AssetMapper] Fix JavaScript compiler load imports from JS strings#53652

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@smnandre
Copy link
Member

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix#53608
LicenseMIT

Add a check to ensure the import is not parsed from a JS string (e.g.console.log(...) in the issue)

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.1" but it seems your PR description refers to branch "6.4".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbotcarsonbot added this to the7.1 milestoneJan 27, 2024
@smnandresmnandre changed the base branch from7.1 to6.4January 27, 2024 15:24
$lineStart =strrpos($fullContent,"\n",$offsetStart -\strlen($fullContent));
// Remove enclosed strings before the import
$lineContentBeforeImport =substr($fullContent,$lineStart,$offsetStart -$lineStart);
$lineWithoutStrings =preg_replace('/\'(?:[^\'\\\\]|\\\\.)*\'|"(?:[^"\\\\]|\\\\.)*"/','',$lineContentBeforeImport);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

template literals (`) are quite common in modern js, and this syntax allows multiline strings making this check quite a challenge

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@kaznovac this PR fixes a bug with console log / deprecation / help messages (cf the original issue)

Handling multi-line strings/comments can reveal itself really complex, and probably would need there some concrete JS parser.

I must admit i doubt any library would use multi-line template comments in source code containing import instructions.. but if/when that happen we could handle it in a later PR ?

WDYT ?

kaznovac and asrorbekh reacted with thumbs up emoji

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

alternative implementation idea: we merge this regexp with the one that checks for imports.
Since regexp are greedy, this will make the filter in one go, with just a quick check at the start of the closure

kaznovac reacted with thumbs up emoji

This comment was marked as outdated.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@nicolas-grekas got it, and it seems to work perfectly ! Thank you :)

Seehttps://regex101.com/r/qFoeoR/1

kaznovac and asrorbekh reacted with rocket emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@smnandre great work && sorry for the late answer

p.s. please note that this method can now be removed

smnandre reacted with thumbs up emoji
@nicolas-grekasnicolas-grekas modified the milestones:7.1,6.4Jan 30, 2024
@nicolas-grekasnicolas-grekasforce-pushed thefix/javascript-compiler-ignore-enquoted branch fromb8aa830 tod70e500CompareFebruary 1, 2024 08:26
@nicolas-grekas
Copy link
Member

Thank you@smnandre.

mtarld reacted with hooray emoji

@nicolas-grekasnicolas-grekas merged commit4fe7828 intosymfony:6.4Feb 1, 2024
nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull requestFeb 20, 2024
…imports from JS strings (smnandre)"This reverts commit4fe7828, reversingchanges made toad1563b.
nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull requestFeb 20, 2024
…imports from JS strings (smnandre)"This reverts commit4fe7828, reversingchanges made toad1563b.
This was referencedFeb 27, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@weaverryanweaverryanweaverryan approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+1 more reviewer

@kaznovackaznovackaznovac left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.4

Development

Successfully merging this pull request may close these issues.

[AssetMapper] Wrong javascript import detection

5 participants

@smnandre@carsonbot@nicolas-grekas@weaverryan@kaznovac

[8]ページ先頭

©2009-2025 Movatter.jp