-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed #358 - quotes in connection instructions on Windows
- Loading branch information
Showing
4 changed files
with
44 additions
and
17 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
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,32 @@ | ||
import { UAParser } from 'ua-parser-js' | ||
|
||
function escapeUnix (arg: string): string { | ||
if (!/^[A-Za-z0-9_\/-]+$/.test(arg)) { | ||
return ('\'' + arg.replace(/'/g, '\'"\'"\'') + '\'').replace(/''/g, '') | ||
} | ||
return arg | ||
} | ||
|
||
function escapeWin (arg: string): string { | ||
if (!/^[A-Za-z0-9_\/-]+$/.test(arg)) { | ||
return '"' + arg.replace(/"/g, '""') + '"' | ||
} | ||
return arg | ||
} | ||
|
||
const isWin = new UAParser().getOS().name === 'Windows' | ||
|
||
export function shellEscape (stringOrArray: string[]|string): string { | ||
const ret = [] | ||
|
||
const escapePath = isWin ? escapeWin : escapeUnix | ||
|
||
if (typeof stringOrArray == 'string') { | ||
return escapePath(stringOrArray) | ||
} else { | ||
stringOrArray.forEach(function (member) { | ||
ret.push(escapePath(member)) | ||
}) | ||
return ret.join(' ') | ||
} | ||
} |
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