Skip to content

Commit 34042dc

Browse files
committed
fix: rename to subpath must fail
1 parent a723b18 commit 34042dc

File tree

4 files changed

+13504
-3
lines changed

4 files changed

+13504
-3
lines changed

dist/virtualfs.js

Lines changed: 13488 additions & 1 deletion
Large diffs are not rendered by default.

dist/virtualfs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/fslib.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ const fileSystemLib = {
163163
cb(...args);
164164
}
165165
}
166-
166+
if (_isSubPathOf(oldPath, newPath)){
167+
callbackInterceptor(new Errors.EINVAL(`Error renaming: ${newPath} cannot be a subpath of ${oldPath}`));
168+
return ;
169+
}
167170
if(Mounts.isMountPath(oldPath) || Mounts.isMountPath(newPath)) {
168171
throw new Errors.EPERM('Mount root directory cannot be deleted.');
169172
} else if(Mounts.isMountSubPath(oldPath) && Mounts.isMountSubPath(newPath)) {

test/test.browser.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ describe('Browser main tests', function () {
185185
expect(failed).to.be.true;
186186
});
187187

188+
it('Should phoenix rename fail if dst is a subpath of src', async function () {
189+
let errored = false;
190+
fs.rename('/a', '/a/b', (err)=>{
191+
if(err){
192+
errored = true;
193+
}
194+
});
195+
await waitForTrue(()=>{return errored;},1000);
196+
expect(errored).to.be.true;
197+
});
198+
188199
function _createFolder(path) {
189200
return new Promise((resolve, reject)=>{
190201
fs.mkdir(path, 777, (err)=>{

0 commit comments

Comments
 (0)