@@ -26,6 +26,7 @@ import {
26
26
LoadSketchRequest ,
27
27
} from './cli-protocol/cc/arduino/cli/commands/v1/commands_pb' ;
28
28
import { Deferred } from '@theia/core/lib/common/promise-util' ;
29
+ import { escapeRegExpCharacters } from '@theia/core/lib/common/strings' ;
29
30
import { ServiceError } from './service-error' ;
30
31
import {
31
32
IsTempSketch ,
@@ -157,7 +158,7 @@ export class SketchesServiceImpl
157
158
const sketchName = segments [ segments . length - 2 ] ;
158
159
const sketchFilename = segments [ segments . length - 1 ] ;
159
160
const sketchFileExtension = segments [ segments . length - 1 ] . replace (
160
- new RegExp ( sketchName ) ,
161
+ new RegExp ( escapeRegExpCharacters ( sketchName ) ) ,
161
162
''
162
163
) ;
163
164
if ( sketchFileExtension !== '.ino' && sketchFileExtension !== '.pde' ) {
@@ -733,10 +734,12 @@ async function isInvalidSketchNameError(
733
734
if ( ino ) {
734
735
const sketchFolderPath = path . dirname ( requestSketchPath ) ;
735
736
const sketchName = path . basename ( sketchFolderPath ) ;
736
- const pattern = `${ invalidSketchNameErrorRegExpPrefix } ${ path . join (
737
- sketchFolderPath ,
738
- `${ sketchName } .ino`
739
- ) } `. replace ( / \\ / g, '\\\\' ) ; // make windows path separator with \\ to have a valid regexp.
737
+ const pattern = escapeRegExpCharacters (
738
+ `${ invalidSketchNameErrorRegExpPrefix } ${ path . join (
739
+ sketchFolderPath ,
740
+ `${ sketchName } .ino`
741
+ ) } `
742
+ ) ;
740
743
if ( new RegExp ( pattern , 'i' ) . test ( cliErr . details ) ) {
741
744
try {
742
745
await fs . access ( requestSketchPath ) ;
0 commit comments