Skip to content

fix(codemod): escape regex characters in import module - #49842

Closed
lakotiasaikiran wants to merge 2 commits into
mui:masterfrom
lakotiasaikiran:fix/codemod-escape-import-module
Closed

lakotiasaikiran wants to merge 2 commits into
mui:masterfrom
lakotiasaikiran:fix/codemod-escape-import-module

Conversation

@lakotiasaikiran

Copy link
Copy Markdown

Problem

The top-level-imports codemod constructs a regular expression using the importModule option without escaping special regex characters.

For example, when importModule is @mui/material.js, the codemod incorrectly matches an import from @mui/materialXjs/Button, even though it belongs to a different package.

Solution

Escaped regex metacharacters in importModule before constructing the regular expression. This ensures that the codemod matches the configured package name literally.

Testing

Added a regression test for incorrect package matching.

Verified that the new test fails before the fix.

Verified that all 3 tests pass after the fix.

Checked code formatting using Prettier.

Verified the changes using git diff --check.

Result

Prevents the codemod from rewriting imports belonging to unrelated packages.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T05:54:27.226283Z a762f50 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lakotiasaikiran
lakotiasaikiran force-pushed the fix/codemod-escape-import-module branch from a762f50 to c3fe1bf Compare November 19, 2026 05:54
@code-infra-dashboard

code-infra-dashboard Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-49842--material-ui.netlify.app/
QR code for https://deploy-preview-49842--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

No regressions in 32 benchmarks · precise to ±9.4% (±15.1% at worst) · ran 4m 15s · details


Check out the code infra dashboard for more information about this PR.

@lakotiasaikiran

Copy link
Copy Markdown
Author

I checked the Argos visual comparison. The only changed snapshot is docs-components-steppers/VerticalLinearStepper.png, which Argos identifies as flaky.

My changes are limited to the top-level-imports codemod and its regression test, so this visual difference appears unrelated to the PR.

The targeted codemod tests are passing locally (3/3).

@zannager zannager added the package: codemod Specific to codemod. label Nov 20, 2026
@ZeeshanTamboli

Copy link
Copy Markdown
Member

Thanks for the PR! importModule is an undocumented option, and its default @mui/material contains no regex metacharacters, so this can't affect the documented usage. The failure case also needs a non-existent package name to match. Since this is a legacy v5 migration codemod and nobody has reported the issue, we'll close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: codemod Specific to codemod.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants