Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 16b54d5

Browse files
author
Akos Kitta
committed
fix: escaped regex chars in pattern
Closes #1600 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent f6275f9 commit 16b54d5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

‎arduino-ide-extension/src/node/sketches-service-impl.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
LoadSketchRequest,
2727
} from './cli-protocol/cc/arduino/cli/commands/v1/commands_pb';
2828
import { Deferred } from '@theia/core/lib/common/promise-util';
29+
import { escapeRegExpCharacters } from '@theia/core/lib/common/strings';
2930
import { ServiceError } from './service-error';
3031
import {
3132
IsTempSketch,
@@ -157,7 +158,7 @@ export class SketchesServiceImpl
157158
const sketchName = segments[segments.length - 2];
158159
const sketchFilename = segments[segments.length - 1];
159160
const sketchFileExtension = segments[segments.length - 1].replace(
160-
new RegExp(sketchName),
161+
new RegExp(escapeRegExpCharacters(sketchName)),
161162
''
162163
);
163164
if (sketchFileExtension !== '.ino' && sketchFileExtension !== '.pde') {
@@ -733,10 +734,12 @@ async function isInvalidSketchNameError(
733734
if (ino) {
734735
const sketchFolderPath = path.dirname(requestSketchPath);
735736
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+
);
740743
if (new RegExp(pattern, 'i').test(cliErr.details)) {
741744
try {
742745
await fs.access(requestSketchPath);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /