Skip to content

Commit 6f1ad3f

Browse files
committed
Block save of isfs class where the class name and file name don't match
1 parent d40a4f4 commit 6f1ad3f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,26 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
185185
// Weirdly, if the file exists on the server we don't actually write its content here.
186186
// Instead we simply return as though we wrote it successfully.
187187
// The actual writing is done by our workspace.onDidSaveTextDocument handler.
188-
// But first check a case for which we should fail the write and leave the document dirty if changed.
188+
// But first check cases for which we should fail the write and leave the document dirty if changed.
189189
if (fileName.split(".").pop().toLowerCase() === "cls") {
190+
// Check if the class is deployed
190191
api.actionIndex([fileName]).then((result) => {
191192
if (result.result.content[0].content.depl) {
192193
throw new Error("Cannot overwrite a deployed class");
193194
}
194195
});
196+
// Check if the class name and file name match
197+
let clsname = "";
198+
const match = content.toString().match(/^[ \t]*Class[ \t]+(%?[\p{L}\d]+(?:\.[\p{L}\d]+)+)/imu);
199+
if (match) {
200+
[, clsname] = match;
201+
}
202+
if (clsname === "") {
203+
throw new Error("Cannot save a malformed class");
204+
}
205+
if (fileName.slice(0, -4) !== clsname) {
206+
throw new Error("Cannot save an isfs class where the class name and file name do not match");
207+
}
195208
}
196209
// Set a -1 mtime cache entry so the actual write by the workspace.onDidSaveTextDocument handler always overwrites.
197210
// By the time we get here VS Code's built-in conflict resolution mechanism will already have interacted with the user.

0 commit comments

Comments
 (0)