fix:sanitize item names before appending file extension on import#8743
fix:sanitize item names before appending file extension on import#8743adwait-bruno wants to merge 1 commit into
Conversation
WalkthroughCollection export and import filename generation now sanitize base names separately from file extensions for request, JavaScript, and environment files. CLI tests cover trailing-period names in both BRU and YML output formats. ChangesFilename normalization
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/bruno-electron/src/utils/collection-import.js`:
- Around line 41-44: Use one shared collision-resolution strategy across both
Electron import flows. In collection-import.js, uniquify sanitized request,
JavaScript, and environment filenames before constructing their paths; in
collection.js, reserve unique request, JavaScript, and environment paths before
asynchronous writes so Promise.all cannot select duplicate destinations.
Preserve the intended extensions and ensure each generated path is unique within
the import operation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2a8a5c79-a416-41bb-bec3-16deaac69212
📒 Files selected for processing (4)
packages/bruno-cli/src/utils/collection.jspackages/bruno-cli/tests/utils/collection/create-collection-from-bruno-object.spec.jspackages/bruno-electron/src/ipc/collection.jspackages/bruno-electron/src/utils/collection-import.js
| let sanitizedFilename = item.filename ? sanitizeName(item.filename) : `${sanitizeName(item.name)}.${format}`; | ||
| const content = await stringifyRequestViaWorker(item, { format }); | ||
| const filePath = path.join(currentPath, sanitizedFilename); | ||
| safeWriteFileSync(filePath, content); |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Use one collision-resolution strategy across both Electron import flows.
Sanitization intentionally causes distinct names to converge, but neither flow reserves or uniquifies the resulting paths. This can overwrite imported data or fail imports; packages/bruno-electron/src/ipc/collection.js is additionally nondeterministic because request and JavaScript writes use Promise.all.
packages/bruno-electron/src/utils/collection-import.jsLines 41-44: uniquify sanitized request filenames.packages/bruno-electron/src/utils/collection-import.jsLines 64-67: uniquify sanitized JavaScript filenames.packages/bruno-electron/src/utils/collection-import.jsLines 79-82: uniquify sanitized environment filenames.packages/bruno-electron/src/ipc/collection.jsLines 1344-1354: reserve unique request paths before writing.packages/bruno-electron/src/ipc/collection.jsLines 1374-1376: reserve unique JavaScript paths before writing.packages/bruno-electron/src/ipc/collection.jsLines 1389-1391: reserve unique environment paths before writing.
📍 Affects 2 files
packages/bruno-electron/src/utils/collection-import.js#L41-L44(this comment)packages/bruno-electron/src/utils/collection-import.js#L64-L67packages/bruno-electron/src/utils/collection-import.js#L79-L82packages/bruno-electron/src/ipc/collection.js#L1344-L1354packages/bruno-electron/src/ipc/collection.js#L1374-L1376packages/bruno-electron/src/ipc/collection.js#L1389-L1391
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/bruno-electron/src/utils/collection-import.js` around lines 41 - 44,
Use one shared collision-resolution strategy across both Electron import flows.
In collection-import.js, uniquify sanitized request, JavaScript, and environment
filenames before constructing their paths; in collection.js, reserve unique
request, JavaScript, and environment paths before asynchronous writes so
Promise.all cannot select duplicate destinations. Preserve the intended
extensions and ensure each generated path is unique within the import operation.
Description
REF:BRU-3250
Cause:Filenames were built by appending the extension and then running the results through sanitizeName(),which stripped trailing dots
Fix:Sanitize the name first and then append the extension
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
.bru,.yml, or.jsextensions..ymlextension.