-
Notifications
You must be signed in to change notification settings - Fork 53
fix: properly quote paths #289
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
Conversation
@coolyuantao is attempting to deploy a commit to the no-veronica Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThis update adds double quotes around file path arguments in several command execution calls to ensure that spaces and special characters in paths are handled as a single argument. Both the Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as DevCommand
participant Formatter as ModuleFormatter
participant Runner as ScriptRunner
Dev->>Formatter: Call formatImportModule(module)
Formatter-->>Dev: Return formatted "--import \"modulePath\""
Dev->>Dev: Extract module path up to first space
Dev->>Runner: Invoke runScript with "node \"modulePath\""
Possibly related PRs
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/baseCommand.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-eggache". (The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. src/commands/dev.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-eggache". (The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes issues with file path quoting to correctly handle paths containing spaces or special characters in various command-line executions.
- Updates the module import formatting to properly handle quoted paths.
- Adds quotes around file paths when executing node scripts.
- Adjusts quoting in both dev and postinstall scripts for improved reliability.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/commands/dev.ts | Refactored module import parsing to correctly split and quote paths. |
src/baseCommand.ts | Updated command and module import formatting by adding quotes. |
scripts/postinstall.mjs | Fixed quoting around the ETS script path in postinstall script. |
const splitIndex = module.indexOf(' '); | ||
if (splitIndex !== -1) { | ||
// --require "path to module" | ||
execArgv.push(module.slice(0, splitIndex), module.slice(splitIndex + 2, -1)); |
Copilot
AI
Mar 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on hardcoded indices for slicing the module string may be brittle if the format changes. Consider using a regular expression to robustly extract the quoted module path.
const splitIndex = module.indexOf(' '); | |
if (splitIndex !== -1) { | |
// --require "path to module" | |
execArgv.push(module.slice(0, splitIndex), module.slice(splitIndex + 2, -1)); | |
const match = module.match(/--require\s+"([^"]+)"/); | |
if (match) { | |
// --require "path to module" | |
execArgv.push('--require', match[1]); |
Copilot uses AI. Check for mistakes.
commit: |
Can you add a test to verify what bug was fixed? |
我补下 |
5d8b9cf
to
6844a14
Compare
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
test/fixtures/test path with space/test-files/test/t e s t.test.js (1)
1-1
: Consider removing redundant 'use strict' directiveJavaScript modules are automatically in strict mode, so this directive is not necessary. However, since this is a test file specifically for path handling with spaces, this is a minor stylistic suggestion.
-'use strict';
🧰 Tools
🪛 Biome (1.9.4)
[error] 1-1: Redundant use strict directive.
The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.(lint/suspicious/noRedundantUseStrict)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (14)
test/fixtures/example-ts-error-stack/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-app/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-app/node_modules/egg/package.json
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-declarations/node_modules/egg-ts-helper/package.json
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-declarations/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-declarations/node_modules/egg/package.json
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-egg-require/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-egg-require/node_modules/egg/package.json
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-import-script/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-import-script/node_modules/egg/package.json
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-require-script/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-require-script/node_modules/egg/package.json
is excluded by!**/node_modules/**
test/fixtures/test-postinstall/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test-postinstall/node_modules/egg/package.json
is excluded by!**/node_modules/**
📒 Files selected for processing (21)
.gitignore
(1 hunks)scripts/postinstall.mjs
(1 hunks)src/baseCommand.ts
(3 hunks)src/commands/dev.ts
(1 hunks)test/commands/cov.test.ts
(1 hunks)test/commands/dev.test.ts
(1 hunks)test/commands/test.test.ts
(1 hunks)test/fixtures/test path with space/example-app/app.ts
(1 hunks)test/fixtures/test path with space/example-app/package.json
(1 hunks)test/fixtures/test path with space/example-declarations/package.json
(1 hunks)test/fixtures/test path with space/example-egg-require/package.json
(1 hunks)test/fixtures/test path with space/example-import-script/package.json
(1 hunks)test/fixtures/test path with space/example-require-script/package.json
(1 hunks)test/fixtures/test path with space/require script.cjs
(1 hunks)test/fixtures/test path with space/require script.mjs
(1 hunks)test/fixtures/test path with space/test-files/package.json
(1 hunks)test/fixtures/test path with space/test-files/test/t e s t.test.js
(1 hunks)test/fixtures/test-postinstall/package.json
(1 hunks)test/fixtures/test-postinstall/typings/app/index.d.ts
(1 hunks)test/fixtures/test-postinstall/typings/config/plugin.d.ts
(1 hunks)test/postinstall.test.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (11)
- test/fixtures/test path with space/require script.mjs
- test/fixtures/test path with space/example-require-script/package.json
- test/fixtures/test path with space/test-files/package.json
- test/fixtures/test path with space/example-declarations/package.json
- test/fixtures/test path with space/require script.cjs
- test/fixtures/test-postinstall/typings/app/index.d.ts
- test/fixtures/test path with space/example-egg-require/package.json
- test/fixtures/test path with space/example-app/package.json
- test/fixtures/test path with space/example-import-script/package.json
- test/fixtures/test-postinstall/typings/config/plugin.d.ts
- test/fixtures/test-postinstall/package.json
🚧 Files skipped from review as they are similar to previous changes (3)
- scripts/postinstall.mjs
- src/commands/dev.ts
- src/baseCommand.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
test/commands/test.test.ts (1)
test/helper.ts (1)
getFixtures
(11-13)
test/postinstall.test.ts (1)
test/helper.ts (2)
getRootDirname
(7-9)getFixtures
(11-13)
test/commands/dev.test.ts (1)
test/helper.ts (1)
getFixtures
(11-13)
🪛 Biome (1.9.4)
test/fixtures/test path with space/test-files/test/t e s t.test.js
[error] 1-1: Redundant use strict directive.
The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.
(lint/suspicious/noRedundantUseStrict)
🔇 Additional comments (13)
test/fixtures/test path with space/example-app/app.ts (1)
1-4
: Simple test fixture function looks goodThis new function provides a straightforward test fixture for validating path handling functionality with spaces in the path. The implementation is clean and focuses on the specific test scenario.
test/fixtures/test path with space/test-files/test/t e s t.test.js (1)
3-9
: Test case looks goodThis simple test case is well-structured for testing path handling with spaces in the filename. The test itself is minimal but sufficient for verifying that the file can be properly loaded and executed.
test/postinstall.test.ts (3)
1-8
: Test setup is well-structuredGood job setting up the test environment with proper imports and configuration. The
NODE_DEBUG
variable is appropriately configured for the postinstall script.
9-23
: Baseline test case is properly implementedThis test verifies the basic functionality of the postinstall script in a standard environment. The assertions check for appropriate output and exit code, which is good practice.
25-39
: Test case for paths with spaces is exactly what was neededThis test case specifically addresses the PR objective of fixing path quoting by testing with a path that contains spaces. Nice work adding this test as requested by the reviewer.
The test correctly:
- Uses a fixture path with spaces
- Sets up the proper environment
- Verifies the expected output and exit code
This will ensure the path quoting fix works correctly.
.gitignore (1)
23-24
: Appropriate .gitignore exceptions for test fixturesThese new exceptions allow tracking of necessary node_modules directories in test fixtures, including those with spaces in their paths. This change supports the new tests and is consistent with the existing pattern of exceptions for test fixtures.
test/commands/cov.test.ts (1)
150-158
: Improved error handling for coverage output formattingThe changes correctly handle the variable formatting of coverage reports by removing the strict stderr check and replacing it with informative comments that explain the expected behavior. This makes the test more robust when dealing with different terminal outputs.
test/commands/test.test.ts (1)
398-408
: Good test case addition for path handlingThis test case properly verifies that the
test
command works correctly with paths containing spaces, which is essential for the PR's goal of fixing path quoting.test/commands/dev.test.ts (5)
235-244
: Well-structured test for basic path handlingThis test correctly verifies that the
dev
command works with spaces in the path. The test uses appropriate fixtures and assertions.
246-254
: Good test for TypeScript declarations with paths containing spacesThis test properly verifies that TypeScript declarations work correctly with paths containing spaces, ensuring that the path quoting fix is applied to this functionality as well.
256-264
: Comprehensive test for egg.require with path spacesThe test ensures that egg's require functionality works correctly with paths containing spaces, which is important for module loading in custom environments.
266-274
: Good verification of --require option with spaces in pathsThis test appropriately checks that the
--require
option correctly handles paths with spaces, which is essential for properly loading CommonJS modules in environments with complex path structures.
276-284
:❓ Verification inconclusive
Thorough test for --import option with spaces in paths
This test verifies that the
--import
option correctly handles paths with spaces, ensuring that ESM modules can be properly imported regardless of special characters in paths.
🏁 Script executed:
#!/bin/bash # Let's verify that the fix is applied to the runScript function that handles path quoting # Find all files with potential path quoting fixes rg -p "runScript" --glob "*.ts" | grep -v "test" | grep -A 5 -B 5 "path"Length of output: 68
Attention: Manual Verification Needed for runScript Function
The test implementation for the
--import
option with paths containing spaces looks solid and confirms that ESM modules function correctly with such paths. However, the verification command to check for path quoting fixes in therunScript
function didn’t return any output. Please manually verify that therunScript
function (in relevant source files outside of tests) properly handles quoting for paths. If no modifications are required or the changes are confirmed by other means, please update the test documentation accordingly.
问题详情某个目录中带有空格、文件中带有空格,导致拼装路径的逻辑出错:
改动思路添加引号,防止路径被空格截断。特殊说明:windows 下的 改动前linux, mac: 改动后:linux, mac: 单测覆盖点
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 28 out of 35 changed files in this pull request and generated no comments.
Files not reviewed (7)
- test/fixtures/test path with space/example-app/package.json: Language not supported
- test/fixtures/test path with space/example-declarations/package.json: Language not supported
- test/fixtures/test path with space/example-egg-require/package.json: Language not supported
- test/fixtures/test path with space/example-import-script/package.json: Language not supported
- test/fixtures/test path with space/example-require-script/package.json: Language not supported
- test/fixtures/test path with space/test-files/package.json: Language not supported
- test/fixtures/test-postinstall/package.json: Language not supported
Comments suppressed due to low confidence (1)
src/commands/dev.ts:47
- If no space is found in the module string, nothing is pushed to execArgv, which may result in a missing argument. Consider adding an else branch that pushes the module as-is to ensure all modules are handled.
const module = this.formatImportModule(r);
6844a14
to
9a9eccc
Compare
有个文件提交漏了,现在应该OK了 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
test/fixtures/test path with space/test-files/test/t e s t.test.js (1)
6-6
: Minor grammar issue in test nameThe test name "should success" is grammatically incorrect. Consider changing to "should succeed" for better readability.
- it('should success', () => { + it('should succeed', () => {test/commands/dev.test.ts (1)
238-239
: Test could benefit from validating error scenariosThe tests validate that the fix works for successful execution, but consider adding tests that verify error scenarios are handled properly when paths with spaces are involved.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (15)
test/fixtures/example-ts-error-stack/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-app/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-app/node_modules/egg/package.json
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-declarations/node_modules/egg-ts-helper/dist/bin.js
is excluded by!**/dist/**
,!**/node_modules/**
test/fixtures/test path with space/example-declarations/node_modules/egg-ts-helper/package.json
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-declarations/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-declarations/node_modules/egg/package.json
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-egg-require/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-egg-require/node_modules/egg/package.json
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-import-script/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-import-script/node_modules/egg/package.json
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-require-script/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test path with space/example-require-script/node_modules/egg/package.json
is excluded by!**/node_modules/**
test/fixtures/test-postinstall/node_modules/egg/index.js
is excluded by!**/node_modules/**
test/fixtures/test-postinstall/node_modules/egg/package.json
is excluded by!**/node_modules/**
📒 Files selected for processing (21)
.gitignore
(2 hunks)scripts/postinstall.mjs
(1 hunks)src/baseCommand.ts
(3 hunks)src/commands/dev.ts
(1 hunks)test/commands/cov.test.ts
(1 hunks)test/commands/dev.test.ts
(1 hunks)test/commands/test.test.ts
(1 hunks)test/fixtures/test path with space/example-app/app.ts
(1 hunks)test/fixtures/test path with space/example-app/package.json
(1 hunks)test/fixtures/test path with space/example-declarations/package.json
(1 hunks)test/fixtures/test path with space/example-egg-require/package.json
(1 hunks)test/fixtures/test path with space/example-import-script/package.json
(1 hunks)test/fixtures/test path with space/example-require-script/package.json
(1 hunks)test/fixtures/test path with space/require script.cjs
(1 hunks)test/fixtures/test path with space/require script.mjs
(1 hunks)test/fixtures/test path with space/test-files/package.json
(1 hunks)test/fixtures/test path with space/test-files/test/t e s t.test.js
(1 hunks)test/fixtures/test-postinstall/package.json
(1 hunks)test/fixtures/test-postinstall/typings/app/index.d.ts
(1 hunks)test/fixtures/test-postinstall/typings/config/plugin.d.ts
(1 hunks)test/postinstall.test.ts
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (19)
- test/fixtures/test path with space/example-import-script/package.json
- test/fixtures/test path with space/example-app/app.ts
- test/fixtures/test path with space/example-require-script/package.json
- test/fixtures/test path with space/example-declarations/package.json
- test/fixtures/test-postinstall/package.json
- test/postinstall.test.ts
- scripts/postinstall.mjs
- test/commands/test.test.ts
- test/fixtures/test path with space/test-files/package.json
- test/fixtures/test path with space/require script.mjs
- test/commands/cov.test.ts
- test/fixtures/test path with space/require script.cjs
- .gitignore
- src/baseCommand.ts
- test/fixtures/test path with space/example-egg-require/package.json
- src/commands/dev.ts
- test/fixtures/test-postinstall/typings/config/plugin.d.ts
- test/fixtures/test path with space/example-app/package.json
- test/fixtures/test-postinstall/typings/app/index.d.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/commands/dev.test.ts (1)
test/helper.ts (1)
getFixtures
(11-13)
🪛 Biome (1.9.4)
test/fixtures/test path with space/test-files/test/t e s t.test.js
[error] 1-1: Redundant use strict directive.
The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.
(lint/suspicious/noRedundantUseStrict)
🔇 Additional comments (3)
test/fixtures/test path with space/test-files/test/t e s t.test.js (1)
1-9
: Well-constructed test file with spaces in the pathThis test file's path explicitly contains spaces to validate the fix for handling paths with spaces in directories or files, which aligns perfectly with the PR objectives. The simple test ensures that basic functionality works in the space-containing environment.
🧰 Tools
🪛 Biome (1.9.4)
[error] 1-1: Redundant use strict directive.
The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.(lint/suspicious/noRedundantUseStrict)
test/commands/dev.test.ts (2)
235-286
: Comprehensive test coverage for paths with spacesThese tests effectively validate the fix for handling paths with spaces in various scenarios:
- Basic application execution
- TypeScript declarations support
- Egg require functionality
- Module imports with --require and --import flags
The tests are well-structured and provide excellent coverage for the issue mentioned in the PR objectives.
267-267
:✅ Verification successful
Verify path handling consistency across environments
The test uses a space in the script filename ('require script.cjs'). This is good for testing but ensure that the path handling logic in the implementation properly quotes and escapes these paths on all operating systems.
🏁 Script executed:
#!/bin/bash # Check how spaces in paths are handled in the implementation # Search for relevant path handling code rg "formatImportModule|runScript" -A 5 -B 5Length of output: 8329
Path Quoting Verification Passed
The implementation has been reviewed, and the path handling logic appears to be robust across environments. In particular:
- In
src/baseCommand.ts
, theformatImportModule
function correctly distinguishes between ESM and non-ESM modes. For ESM, it usespathToFileURL
to safely convert file paths, while on Windows it appliespath.win32.normalize
along with appropriate escaping.- Multiple uses of
runScript
(e.g., in bothsrc/baseCommand.ts
andscripts/postinstall.mjs
) confirm that command strings are wrapped in quotes, ensuring that paths with spaces (like"require script.cjs"
) are handled correctly.Based on these findings, there is no further action required regarding path quoting.
感谢,ci 过了就合并发布 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #289 +/- ##
==========================================
- Coverage 95.85% 90.70% -5.15%
==========================================
Files 22 18 -4
Lines 1085 1108 +23
Branches 172 153 -19
==========================================
- Hits 1040 1005 -35
- Misses 45 103 +58 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@coolyuantao 感谢参与开源❤️ |
[skip ci] ## [7.3.1](v7.3.0...v7.3.1) (2025-04-19) ### Bug Fixes * properly quote paths ([#289](#289)) ([dcff9ac](dcff9ac))
Summary by CodeRabbit
Bug Fixes
New Features
Chores
.gitignore
to allow tracking of specificnode_modules
directories.package.json
files for various example projects to specify configurations.