forked from laurent22/joplin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for laurent22#906, 1) windows paths like C:\a\b weren't accepted …
…because backslashes were treated as escape sequences, 2) common paths like C:\Program Files\Foo\Foo.exe weren't accepted because of the space in the path
- Loading branch information
Ben Fisher
committed
Oct 31, 2018
1 parent
e41896d
commit b2a1a4f
Showing
4 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require('app-module-path').addPath(__dirname); | ||
|
||
const { removeDiacritics, escapeFilename, wrap, prepareCmdStringWindows, splitCommandString, padLeft, toTitleCase } = require('lib/string-utils.js'); | ||
|
||
process.on('unhandledRejection', (reason, p) => { | ||
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); | ||
}); | ||
|
||
describe('StringUtils', function() { | ||
|
||
beforeEach(async (done) => { | ||
done(); | ||
}); | ||
|
||
it('adds quotes if whole string is an existing file', async (done) => { | ||
let fnExists = async (fpath) => true; | ||
let ret = await prepareCmdStringWindows('abc def /g', fnExists); | ||
expect(ret).toBe('"abc def /g"'); | ||
ret = await prepareCmdStringWindows('abc def', fnExists); | ||
expect(ret).toBe('"abc def"'); | ||
ret = await prepareCmdStringWindows('abc "def"', fnExists); | ||
expect(ret).toBe('abc "def"'); | ||
ret = await prepareCmdStringWindows('abc', fnExists); | ||
expect(ret).toBe('abc'); | ||
done(); | ||
}); | ||
|
||
it('doesn\'t add quotes if whole string is not an existing file', async (done) => { | ||
let fnExists = async (fpath) => false; | ||
let ret = await prepareCmdStringWindows('abc def /g', fnExists); | ||
expect(ret).toBe('abc def /g'); | ||
ret = await prepareCmdStringWindows('abc def', fnExists); | ||
expect(ret).toBe('abc def'); | ||
ret = await prepareCmdStringWindows('abc "def"', fnExists); | ||
expect(ret).toBe('abc "def"'); | ||
ret = await prepareCmdStringWindows('abc', fnExists); | ||
expect(ret).toBe('abc'); | ||
done(); | ||
}); | ||
|
||
it('doubles backslashes', async (done) => { | ||
let fnExists = async (fpath) => false; | ||
let ret = await prepareCmdStringWindows('C:\\Program Files\\Foo\\F', fnExists); | ||
expect(ret).toBe('C:\\\\Program Files\\\\Foo\\\\F'); | ||
ret = await prepareCmdStringWindows('a/b/ c /d', fnExists); | ||
expect(ret).toBe('a/b/ c /d'); | ||
ret = await prepareCmdStringWindows('a\\b c /d', fnExists); | ||
expect(ret).toBe('a\\\\b c /d'); | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters