Skip to content

Commit e0b9ab2

Browse files
Wrap Linux filepath in quotes so spaces aren't seen as arguments
1 parent fa3fd0f commit e0b9ab2

File tree

8 files changed

+1752
-1593
lines changed

8 files changed

+1752
-1593
lines changed

.eslintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ module.exports = {
2020
'tjw-jsdoc'
2121
],
2222
rules: {
23-
// Turn on after https://github.com/eslint/eslint/issues/14745 resolved
24-
'jsdoc/check-examples': 0,
2523
'jsdoc/require-example': 1
2624
}
2725
};

package-lock.json

Lines changed: 1681 additions & 1572 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "create-desktop-shortcuts",
33
"main": "index.js",
4-
"version": "1.6.1",
4+
"version": "1.7.0",
55
"description": "Easy API to create desktop shortcuts with Node",
66
"author": "The Jared Wilcurt",
77
"keywords": [
@@ -30,12 +30,12 @@
3030
"which": "^2.0.2"
3131
},
3232
"devDependencies": {
33-
"@babel/core": "^7.18.2",
33+
"@babel/core": "^7.18.5",
3434
"@babel/eslint-parser": "^7.18.2",
3535
"eslint": "^8.17.0",
3636
"eslint-config-tjw-base": "^2.0.0",
3737
"eslint-config-tjw-jest": "^2.0.0",
38-
"eslint-config-tjw-jsdoc": "^1.0.1",
38+
"eslint-config-tjw-jsdoc": "^1.0.2",
3939
"eslint-plugin-jsdoc": "^39.3.2",
4040
"fs-extra": "8.1.0",
4141
"jest": "24.9.0",

src/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const library = {
3232
// Set defaults
3333
let type = 'Type=Application';
3434
let terminal = 'Terminal=false';
35-
let exec = 'Exec=' + options.linux.filePath;
35+
let exec = 'Exec="' + options.linux.filePath + '"';
3636
let name = 'Name=' + path.parse(options.linux.filePath).name;
3737
let comment = '';
3838
let icon = '';

src/validation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const validation = {
171171
* object is a boolean, and if not, give it the correct default value.
172172
*
173173
* @example
174-
* options = defaultBoolean(options);
174+
* options = defaultBoolean(options, 'linux', 'chmod', true);
175175
*
176176
* @param {object} options User's options
177177
* @param {string} operatingSystem 'windows', 'linux', or 'osx'

tests/e2e.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* @author TheJaredWilcurt
44
*/
55

6+
const timeLabel = '| | Executed in';
7+
console.time(timeLabel);
8+
69
const fs = require('fs-extra');
710
const path = require('path');
811

@@ -74,6 +77,7 @@ function alert (pass, message) {
7477
console.log('\n ______________ ' + fill('_'));
7578
console.log('| |' + fill(' ') + '|');
7679
console.log('| E2E ' + state + ' | ' + message + ' |');
80+
console.timeEnd(timeLabel);
7781
console.log('| |' + fill(' ') + '|');
7882
console.log(' ¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ' + fill('¯') + '\n\n');
7983

tests/src/library.test.js

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('library', () => {
6565
'Version=1.0',
6666
'Type=Application',
6767
'Terminal=false',
68-
'Exec=/home/DUMMY/file.ext',
68+
'Exec="/home/DUMMY/file.ext"',
6969
'Name=file'
7070
].join('\n'));
7171
});
@@ -80,7 +80,7 @@ describe('library', () => {
8080
'Version=1.0',
8181
'Type=Application',
8282
'Terminal=true',
83-
'Exec=/home/DUMMY/file.ext',
83+
'Exec="/home/DUMMY/file.ext"',
8484
'Name=file'
8585
].join('\n'));
8686
});
@@ -96,7 +96,7 @@ describe('library', () => {
9696
'Version=1.0',
9797
'Type=Directory',
9898
'Terminal=false',
99-
'Exec=/home/DUMMY',
99+
'Exec="/home/DUMMY"',
100100
'Name=DUMMY'
101101
].join('\n'));
102102
});
@@ -111,7 +111,7 @@ describe('library', () => {
111111
'Version=1.0',
112112
'Type=Application',
113113
'Terminal=false',
114-
'Exec=/home/DUMMY/file.ext',
114+
'Exec="/home/DUMMY/file.ext"',
115115
'Name=Test'
116116
].join('\n'));
117117
});
@@ -126,7 +126,7 @@ describe('library', () => {
126126
'Version=1.0',
127127
'Type=Application',
128128
'Terminal=false',
129-
'Exec=/home/DUMMY/file.ext',
129+
'Exec="/home/DUMMY/file.ext"',
130130
'Name=file',
131131
'comment=Test'
132132
].join('\n'));
@@ -142,7 +142,7 @@ describe('library', () => {
142142
'Version=1.0',
143143
'Type=Application',
144144
'Terminal=false',
145-
'Exec=/home/DUMMY/file.ext',
145+
'Exec="/home/DUMMY/file.ext"',
146146
'Name=file',
147147
'Icon=/home/DUMMY/icon.png'
148148
].join('\n'));
@@ -158,7 +158,23 @@ describe('library', () => {
158158
'Version=1.0',
159159
'Type=Application',
160160
'Terminal=false',
161-
'Exec=/home/DUMMY/file.ext -f --version',
161+
'Exec="/home/DUMMY/file.ext" -f --version',
162+
'Name=file'
163+
].join('\n'));
164+
});
165+
166+
test('Arguments with file path space', () => {
167+
options.linux.filePath = '/home/DUMMY/foo bar/file.ext';
168+
options.linux.arguments = '-f --version';
169+
170+
expect(library.generateLinuxFileData(options))
171+
.toEqual([
172+
'#!/user/bin/env xdg-open',
173+
'[Desktop Entry]',
174+
'Version=1.0',
175+
'Type=Application',
176+
'Terminal=false',
177+
'Exec="/home/DUMMY/foo bar/file.ext" -f --version',
162178
'Name=file'
163179
].join('\n'));
164180
});
@@ -199,7 +215,7 @@ describe('library', () => {
199215
'Version=1.0',
200216
'Type=Application',
201217
'Terminal=false',
202-
'Exec=/home/DUMMY/file.ext',
218+
'Exec="/home/DUMMY/file.ext"',
203219
'Name=file'
204220
].join('\n')
205221
);
@@ -222,7 +238,7 @@ describe('library', () => {
222238
'Version=1.0',
223239
'Type=Application',
224240
'Terminal=false',
225-
'Exec=/home/DUMMY/file.ext',
241+
'Exec="/home/DUMMY/file.ext"',
226242
'Name=file'
227243
].join('\n'),
228244
'Successfully errored'
@@ -246,7 +262,7 @@ describe('library', () => {
246262
'Version=1.0',
247263
'Type=Application',
248264
'Terminal=false',
249-
'Exec=/home/DUMMY/file.ext',
265+
'Exec="/home/DUMMY/file.ext"',
250266
'Name=file'
251267
].join('\n')
252268
);
@@ -279,7 +295,7 @@ describe('library', () => {
279295
'Version=1.0',
280296
'Type=Application',
281297
'Terminal=false',
282-
'Exec=/home/DUMMY/file.ext',
298+
'Exec="/home/DUMMY/file.ext"',
283299
'Name=file'
284300
].join('\n')
285301
);
@@ -411,6 +427,35 @@ describe('library', () => {
411427
);
412428
});
413429

430+
test('Windows arguments', () => {
431+
options.windows.arguments = '--force';
432+
433+
expect(library.makeWindowsShortcut(options))
434+
.toEqual(true);
435+
436+
expect(customLogger)
437+
.not.toHaveBeenCalled();
438+
439+
expect(childProcess.execSync)
440+
.not.toHaveBeenCalled();
441+
442+
expect(childProcess.spawnSync)
443+
.toHaveBeenLastCalledWith(
444+
'wscript',
445+
[
446+
library.produceWindowsVBSPath(),
447+
'C:/Users/DUMMY/Desktop/file.lnk',
448+
'C:/file.ext',
449+
'--force',
450+
'',
451+
'',
452+
'C:/file.ext',
453+
1,
454+
''
455+
]
456+
);
457+
});
458+
414459
test('Windows.vbs not found', () => {
415460
const fsExistsSync = fs.existsSync;
416461
fs.existsSync = jest.fn(() => {
@@ -669,7 +714,7 @@ describe('library', () => {
669714
'Version=1.0',
670715
'Type=Application',
671716
'Terminal=false',
672-
'Exec=/home/DUMMY/file.ext',
717+
'Exec="/home/DUMMY/file.ext"',
673718
'Name=file'
674719
].join('\n')
675720
);
@@ -767,7 +812,7 @@ describe('library', () => {
767812
'Version=1.0',
768813
'Type=Application',
769814
'Terminal=false',
770-
'Exec=/home/DUMMY/file.ext',
815+
'Exec="/home/DUMMY/file.ext"',
771816
'Name=file'
772817
].join('\n')
773818
);
@@ -844,7 +889,7 @@ describe('library', () => {
844889
'Version=1.0',
845890
'Type=Application',
846891
'Terminal=false',
847-
'Exec=/home/DUMMY/file.ext',
892+
'Exec="/home/DUMMY/file.ext"',
848893
'Name=file'
849894
].join('\n')
850895
);

tests/testHelpers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ const testHelpers = {
186186
'icon.bmp': 'text',
187187
Desktop: {},
188188
folder: {}
189+
},
190+
'/home/DUMMY/foo bar': {
191+
'file.ext': 'text'
189192
}
190193
};
191194
if (os.platform() === 'win32') {

0 commit comments

Comments
 (0)