fix: normalize Windows paths for cross-platform compatibility#7185
fix: normalize Windows paths for cross-platform compatibility#7185bijin-bruno merged 2 commits intousebruno:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 WalkthroughAdds internal POSIX path normalization via a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/bruno-electron/src/utils/workspace-config.js (2)
341-341:addCollectionToWorkspacestores the path differently fromaddApiSpecToWorkspace.Line 341 posixifies and stores the raw (potentially absolute) path.
addApiSpecToWorkspace(line 459) runsmakeRelativePathfirst, ensuring a relative POSIX path is stored in the YAML. For consistency, and to avoid embedding absolute Windows paths (C:/...) into workspace files (which break when the file is opened on macOS/Linux —path.isAbsolute('C:/...')returnsfalseon POSIX), this function should do the same.♻️ Suggested refactor
const normalizedCollection = { name: collection.name.trim(), - path: posixifyPath(collection.path.trim()) + path: makeRelativePath(workspacePath, collection.path.trim()) };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-electron/src/utils/workspace-config.js` at line 341, addCollectionToWorkspace currently stores collection.path after only posixifying it, which can preserve absolute Windows paths; update addCollectionToWorkspace to mirror addApiSpecToWorkspace by passing collection.path through makeRelativePath(...) before posixifyPath(...) so the YAML stores a relative POSIX path; locate the collection.path assignment in addCollectionToWorkspace and replace the direct posixifyPath(collection.path.trim()) usage with posixifyPath(makeRelativePath(collection.path).trim()) (or equivalent ordering used by addApiSpecToWorkspace) to ensure consistent cross-platform relative paths.
8-9: Consider a defensive type guard inposixifyPath.
p.replace(...)will throw ifpisnull,undefined, or a non-string. All current call sites are properly guarded (ternary checks /isValidCollectionEntrypre-validation), so there's no immediate risk — but a guard makes the helper self-documenting about its contract.🛡️ Suggested guard
-const posixifyPath = (p) => p.replace(/\\/g, '/'); +const posixifyPath = (p) => (typeof p === 'string' ? p.replace(/\\/g, '/') : p);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-electron/src/utils/workspace-config.js` around lines 8 - 9, The helper posixifyPath currently calls p.replace(...) which will throw if p is null/undefined or not a string; add a defensive type guard at the start of posixifyPath (e.g., check typeof p === 'string') and if the check fails return the original value (or an empty string if you prefer) so the function never throws on bad inputs; update any tests or callers if they rely on an exception, and keep the function name posixifyPath unchanged so callers like isValidCollectionEntry continue to work.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/bruno-electron/src/utils/workspace-config.js`:
- Line 341: addCollectionToWorkspace currently stores collection.path after only
posixifying it, which can preserve absolute Windows paths; update
addCollectionToWorkspace to mirror addApiSpecToWorkspace by passing
collection.path through makeRelativePath(...) before posixifyPath(...) so the
YAML stores a relative POSIX path; locate the collection.path assignment in
addCollectionToWorkspace and replace the direct
posixifyPath(collection.path.trim()) usage with
posixifyPath(makeRelativePath(collection.path).trim()) (or equivalent ordering
used by addApiSpecToWorkspace) to ensure consistent cross-platform relative
paths.
- Around line 8-9: The helper posixifyPath currently calls p.replace(...) which
will throw if p is null/undefined or not a string; add a defensive type guard at
the start of posixifyPath (e.g., check typeof p === 'string') and if the check
fails return the original value (or an empty string if you prefer) so the
function never throws on bad inputs; update any tests or callers if they rely on
an exception, and keep the function name posixifyPath unchanged so callers like
isValidCollectionEntry continue to work.
* fix: normalize Windows paths for cross-platform compatibility in workspace * fixes
Description
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit