Skip to content
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

fix(filesystem): allow copy if from is not parent of to #546

Merged
merged 8 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions filesystem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,8 @@
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"path-cross": "^0.0.3"
}
}
17 changes: 16 additions & 1 deletion filesystem/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ import type {
Directory,
} from './definitions';

import { resolve } from 'path-cross';


export function isPathParent(parent: string, children: string): boolean {
parent = resolve(parent);
children = resolve(children);
const pathsA = parent.split('/');
const pathsB = children.split('/');

return (
parent !== children &&
pathsA.every((value, index) => value === pathsB[index])
);
}

export class FilesystemWeb extends WebPlugin implements FilesystemPlugin {
DB_VERSION = 1;
DB_NAME = 'Disc';
Expand Down Expand Up @@ -431,7 +446,7 @@ export class FilesystemWeb extends WebPlugin implements FilesystemPlugin {
return;
}

if (toPath.startsWith(fromPath)) {
if (isPathParent(fromPath, toPath)) {
throw Error('To path cannot contain the from path');
}

Expand Down
Loading