Skip to content

Commit

Permalink
Wrap Linux filepath in quotes so spaces aren't seen as arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJaredWilcurt authored Jun 15, 2022
1 parent fa3fd0f commit e0b9ab2
Show file tree
Hide file tree
Showing 8 changed files with 1,752 additions and 1,593 deletions.
2 changes: 0 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ module.exports = {
'tjw-jsdoc'
],
rules: {
// Turn on after https://github.com/eslint/eslint/issues/14745 resolved
'jsdoc/check-examples': 0,
'jsdoc/require-example': 1
}
};
3,253 changes: 1,681 additions & 1,572 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-desktop-shortcuts",
"main": "index.js",
"version": "1.6.1",
"version": "1.7.0",
"description": "Easy API to create desktop shortcuts with Node",
"author": "The Jared Wilcurt",
"keywords": [
Expand Down Expand Up @@ -30,12 +30,12 @@
"which": "^2.0.2"
},
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/core": "^7.18.5",
"@babel/eslint-parser": "^7.18.2",
"eslint": "^8.17.0",
"eslint-config-tjw-base": "^2.0.0",
"eslint-config-tjw-jest": "^2.0.0",
"eslint-config-tjw-jsdoc": "^1.0.1",
"eslint-config-tjw-jsdoc": "^1.0.2",
"eslint-plugin-jsdoc": "^39.3.2",
"fs-extra": "8.1.0",
"jest": "24.9.0",
Expand Down
2 changes: 1 addition & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const library = {
// Set defaults
let type = 'Type=Application';
let terminal = 'Terminal=false';
let exec = 'Exec=' + options.linux.filePath;
let exec = 'Exec="' + options.linux.filePath + '"';
let name = 'Name=' + path.parse(options.linux.filePath).name;
let comment = '';
let icon = '';
Expand Down
2 changes: 1 addition & 1 deletion src/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const validation = {
* object is a boolean, and if not, give it the correct default value.
*
* @example
* options = defaultBoolean(options);
* options = defaultBoolean(options, 'linux', 'chmod', true);
*
* @param {object} options User's options
* @param {string} operatingSystem 'windows', 'linux', or 'osx'
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* @author TheJaredWilcurt
*/

const timeLabel = '| | Executed in';
console.time(timeLabel);

const fs = require('fs-extra');
const path = require('path');

Expand Down Expand Up @@ -74,6 +77,7 @@ function alert (pass, message) {
console.log('\n ______________ ' + fill('_'));
console.log('| |' + fill(' ') + '|');
console.log('| E2E ' + state + ' | ' + message + ' |');
console.timeEnd(timeLabel);
console.log('| |' + fill(' ') + '|');
console.log(' ¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ' + fill('¯') + '\n\n');

Expand Down
73 changes: 59 additions & 14 deletions tests/src/library.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file'
].join('\n'));
});
Expand All @@ -80,7 +80,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=true',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file'
].join('\n'));
});
Expand All @@ -96,7 +96,7 @@ describe('library', () => {
'Version=1.0',
'Type=Directory',
'Terminal=false',
'Exec=/home/DUMMY',
'Exec="/home/DUMMY"',
'Name=DUMMY'
].join('\n'));
});
Expand All @@ -111,7 +111,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=Test'
].join('\n'));
});
Expand All @@ -126,7 +126,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file',
'comment=Test'
].join('\n'));
Expand All @@ -142,7 +142,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file',
'Icon=/home/DUMMY/icon.png'
].join('\n'));
Expand All @@ -158,7 +158,23 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext -f --version',
'Exec="/home/DUMMY/file.ext" -f --version',
'Name=file'
].join('\n'));
});

test('Arguments with file path space', () => {
options.linux.filePath = '/home/DUMMY/foo bar/file.ext';
options.linux.arguments = '-f --version';

expect(library.generateLinuxFileData(options))
.toEqual([
'#!/user/bin/env xdg-open',
'[Desktop Entry]',
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec="/home/DUMMY/foo bar/file.ext" -f --version',
'Name=file'
].join('\n'));
});
Expand Down Expand Up @@ -199,7 +215,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file'
].join('\n')
);
Expand All @@ -222,7 +238,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file'
].join('\n'),
'Successfully errored'
Expand All @@ -246,7 +262,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file'
].join('\n')
);
Expand Down Expand Up @@ -279,7 +295,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file'
].join('\n')
);
Expand Down Expand Up @@ -411,6 +427,35 @@ describe('library', () => {
);
});

test('Windows arguments', () => {
options.windows.arguments = '--force';

expect(library.makeWindowsShortcut(options))
.toEqual(true);

expect(customLogger)
.not.toHaveBeenCalled();

expect(childProcess.execSync)
.not.toHaveBeenCalled();

expect(childProcess.spawnSync)
.toHaveBeenLastCalledWith(
'wscript',
[
library.produceWindowsVBSPath(),
'C:/Users/DUMMY/Desktop/file.lnk',
'C:/file.ext',
'--force',
'',
'',
'C:/file.ext',
1,
''
]
);
});

test('Windows.vbs not found', () => {
const fsExistsSync = fs.existsSync;
fs.existsSync = jest.fn(() => {
Expand Down Expand Up @@ -669,7 +714,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file'
].join('\n')
);
Expand Down Expand Up @@ -767,7 +812,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file'
].join('\n')
);
Expand Down Expand Up @@ -844,7 +889,7 @@ describe('library', () => {
'Version=1.0',
'Type=Application',
'Terminal=false',
'Exec=/home/DUMMY/file.ext',
'Exec="/home/DUMMY/file.ext"',
'Name=file'
].join('\n')
);
Expand Down
3 changes: 3 additions & 0 deletions tests/testHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ const testHelpers = {
'icon.bmp': 'text',
Desktop: {},
folder: {}
},
'/home/DUMMY/foo bar': {
'file.ext': 'text'
}
};
if (os.platform() === 'win32') {
Expand Down

0 comments on commit e0b9ab2

Please sign in to comment.