forked from chjj/pty.js
-
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.
Merge pull request chjj#47 from Tyriar/41_args_as_string
Allow passing args as pre-escaped CommandLine format (string) on Windows
- Loading branch information
Showing
7 changed files
with
124 additions
and
74 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,5 @@ | ||
/** | ||
* Copyright (c) 2017, Daniel Imms (MIT License). | ||
*/ | ||
|
||
export type ArgvOrCommandLine = string[] | string; |
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
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,73 @@ | ||
if (process.platform !== 'win32') { | ||
return; | ||
} | ||
|
||
var argsToCommandLine = require('../lib/windowsPtyAgent').argsToCommandLine; | ||
var assert = require("assert"); | ||
|
||
function check(file, args, expected) { | ||
assert.equal(argsToCommandLine(file, args), expected); | ||
} | ||
|
||
describe("argsToCommandLine", function() { | ||
describe("Plain strings", function() { | ||
it("doesn't quote plain string", function() { | ||
check('asdf', [], 'asdf'); | ||
}); | ||
it("doesn't escape backslashes", function() { | ||
check('\\asdf\\qwer\\', [], '\\asdf\\qwer\\'); | ||
}); | ||
it("doesn't escape multiple backslashes", function() { | ||
check('asdf\\\\qwer', [], 'asdf\\\\qwer'); | ||
}); | ||
it("adds backslashes before quotes", function() { | ||
check('"asdf"qwer"', [], '\\"asdf\\"qwer\\"'); | ||
}); | ||
it("escapes backslashes before quotes", function() { | ||
check('asdf\\"qwer', [], 'asdf\\\\\\"qwer'); | ||
}); | ||
}); | ||
|
||
describe("Quoted strings", function() { | ||
it("quotes string with spaces", function() { | ||
check('asdf qwer', [], '"asdf qwer"'); | ||
}); | ||
it("quotes empty string", function() { | ||
check('', [], '""'); | ||
}); | ||
it("quotes string with tabs", function() { | ||
check('asdf\tqwer', [], '"asdf\tqwer"'); | ||
}); | ||
it("escapes only the last backslash", function() { | ||
check('\\asdf \\qwer\\', [], '"\\asdf \\qwer\\\\"'); | ||
}); | ||
it("doesn't escape multiple backslashes", function() { | ||
check('asdf \\\\qwer', [], '"asdf \\\\qwer"'); | ||
}); | ||
it("adds backslashes before quotes", function() { | ||
check('"asdf "qwer"', [], '"\\"asdf \\"qwer\\""'); | ||
}); | ||
it("escapes backslashes before quotes", function() { | ||
check('asdf \\"qwer', [], '"asdf \\\\\\"qwer"'); | ||
}); | ||
it("escapes multiple backslashes at the end", function() { | ||
check('asdf qwer\\\\', [], '"asdf qwer\\\\\\\\"'); | ||
}); | ||
}); | ||
|
||
describe("Multiple arguments", function() { | ||
it("joins arguments with spaces", function() { | ||
check('asdf', ['qwer zxcv', '', '"'], 'asdf "qwer zxcv" "" \\"'); | ||
}); | ||
}); | ||
|
||
describe("Args as CommandLine", function() { | ||
it("should handle empty string", function() { | ||
check('file', '', 'file'); | ||
}); | ||
it("should not change args", function() { | ||
check('file', 'foo bar baz', 'file foo bar baz'); | ||
check('file', 'foo \\ba"r \baz', 'file foo \\ba"r \baz'); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.