Skip to content

Commit f6d112e

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
fix: escaped regex chars in pattern
Closes #1600 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent cc2d557 commit f6d112e

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

arduino-ide-extension/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"@types/deepmerge": "^2.2.0",
4646
"@types/glob": "^7.2.0",
4747
"@types/google-protobuf": "^3.7.2",
48-
"@types/is-valid-path": "^0.1.0",
4948
"@types/js-yaml": "^3.12.2",
5049
"@types/keytar": "^4.4.0",
5150
"@types/lodash.debounce": "^4.0.6",

arduino-ide-extension/src/electron-main/theia/electron-main-application.ts

-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
CLOSE_PLOTTER_WINDOW,
2828
SHOW_PLOTTER_WINDOW,
2929
} from '../../common/ipc-communication';
30-
import isValidPath = require('is-valid-path');
3130
import { ErrnoException } from '../../node/utils/errors';
3231

3332
app.commandLine.appendSwitch('disable-http-cache');
@@ -206,9 +205,6 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
206205
maybePath: string,
207206
cwd: string
208207
): Promise<string | undefined> {
209-
if (!isValidPath(maybePath)) {
210-
return undefined;
211-
}
212208
if (isAbsolute(maybePath)) {
213209
return maybePath;
214210
}

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

+8-5
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,
@@ -158,7 +159,7 @@ export class SketchesServiceImpl
158159
const sketchName = segments[segments.length - 2];
159160
const sketchFilename = segments[segments.length - 1];
160161
const sketchFileExtension = segments[segments.length - 1].replace(
161-
new RegExp(sketchName),
162+
new RegExp(escapeRegExpCharacters(sketchName)),
162163
''
163164
);
164165
if (sketchFileExtension !== '.ino' && sketchFileExtension !== '.pde') {
@@ -746,10 +747,12 @@ async function isInvalidSketchNameError(
746747
if (ino) {
747748
const sketchFolderPath = path.dirname(requestSketchPath);
748749
const sketchName = path.basename(sketchFolderPath);
749-
const pattern = `${invalidSketchNameErrorRegExpPrefix}${path.join(
750-
sketchFolderPath,
751-
`${sketchName}.ino`
752-
)}`.replace(/\\/g, '\\\\'); // make windows path separator with \\ to have a valid regexp.
750+
const pattern = escapeRegExpCharacters(
751+
`${invalidSketchNameErrorRegExpPrefix}${path.join(
752+
sketchFolderPath,
753+
`${sketchName}.ino`
754+
)}`
755+
);
753756
if (new RegExp(pattern, 'i').test(cliErr.details)) {
754757
try {
755758
await fs.access(requestSketchPath);

yarn.lock

-5
Original file line numberDiff line numberDiff line change
@@ -3118,11 +3118,6 @@
31183118
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz#0ea7b61496902b95890dc4c3a116b60cb8dae812"
31193119
integrity sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==
31203120

3121-
"@types/is-valid-path@^0.1.0":
3122-
version "0.1.0"
3123-
resolved "https://registry.yarnpkg.com/@types/is-valid-path/-/is-valid-path-0.1.0.tgz#d5c6e96801303112c9626d44268c6fabc72d272f"
3124-
integrity sha512-2ontWtpN8O2nf5S7EjDDJ0DwrRa2t7wmS3Wmo322yWYG6yFBYC1QCaLhz4Iz+mzJy8Kf4zP5yVyEd1ANPDmOFQ==
3125-
31263121
"@types/js-yaml@^3.12.2":
31273122
version "3.12.7"
31283123
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.12.7.tgz#330c5d97a3500e9c903210d6e49f02964af04a0e"

0 commit comments

Comments
 (0)