File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
src/providers/FileSystemProvider Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff 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 ] * C l a s s [ \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.
You can’t perform that action at this time.
0 commit comments