Skip to content

Commit 16b1558

Browse files
authored
Escape single quotes(') and right single quotation mark(’) in the file path (#3)
* Escape Single quotes in the file path * Escape right single quotation mark(u+2019 == ’) * Improve comment and function declaration
1 parent 2e95dcd commit 16b1558

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ function generateCommands (filePaths, customLogger) {
2929
for (let filePath of filePaths) {
3030
const normalizedFile = normalizeFile(filePath, customLogger);
3131
if (normalizedFile) {
32+
// Escape (') and (’) in the file path for PowerShell syntax
33+
const safeFilePath = normalizedFile
34+
.replace(/'/g, "''")
35+
.replace(//g, "’’");
36+
3237
const command = [
33-
'(New-Object -COM WScript.Shell).CreateShortcut(',
34-
filePath,
35-
');'
36-
].join('\'');
38+
'(New-Object -COM WScript.Shell).CreateShortcut(\'',
39+
safeFilePath,
40+
'\');'
41+
].join('');
3742
commands.push(command);
3843
}
3944
}

0 commit comments

Comments
 (0)