-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fuzz the
escape
function, add escaping for interpolation characters (…
…#152) * Fuzz `escape` function on unix Update the fuzz target to test both the `quote()` and `escape()` functions (instead of just `quote()`). Fuzzing the `escape()` function is roughly identical to fuzzing the `quote()` function, except that the provided buffer is stripped of whitespace before echoing to ensure all characters in the string are part of the first argument. * Refactor index.fuzz.cjs to reduce duplication and fix Windows args - Define `WHITESPACE_REGEX` to avoid rewriting the regular expression to (really) capture all whitespace. - Update the error message for unexpected output so it's different for the two tested functions. - Define the `options` for `quote()` and `escape()` prior to the resp. fuzz function as the value is the same for both. - Fix `prepareArg` for Windows cmd.exe when quoted=false * Update unix escaping based on fuzzing Update escaping for unix platforms based on the existing fuzz corpus. The unix escape logic now expects a boolean value indicating whether interpolation is enabled and if so will escape more characters. This is needed when the `escape()` API functions is used because the result may be used in a context where interpolation is enabled. Hence, main assumes interpolation is enabled unless specified otherwise. * Escape ")" for unix with interpolation This escape relates to the escaping of "(" in that shells (tested Zsh) on unix with interpolation interpret parenthesis in a special way. * Escape "<" and ">" for unix with interpolation These characters are used for redirecting input/output streams so should be escaped. * Escape "#" at the start of args for unix with interpolation The "#" character has a special meaning at the start of an argument. * Escape "|" in args for unix with interpolation The "|" character means a logical or. * Escape ";" in args for unix with interpolation The ";" character denotes the end of a singular command, after which a new command starts. * Escape "&" in args for unix with interpolation The "&" character means a logical and. * Escape "*" and "?" in args for unix with interpolation The characters "*" and "?" can be used for string expansion if there are no quotes. In Zsh these characters are always expanded (if unsuccessful the command will error). On bash and dash these characters will only be expanded if possible (otherwise they will appear literally). As the context in which Shescape operates is unknown, for both shell styles the characters always need to be escaped. * Escape leading "~" in args for unix with interpolation The "~" character has a special meaning (the home directory) either: 1. as the only character in the argument (bash, dash) 2. at the start of an argument (Zsh) Both cases can be efficiently escaped by prefix "~" with a backslash, this works regardless of whether or not the argument is more than one string in bash and dash. * Escape "[" and "]" for Zsh with interpolation Specifically in Zsh, "[" and "]" can be used for string expansion if there are no quotes. So, the err on the safe side, they will always be escaped when `interpolation` is true. * Escape leading "=" for Zsh with interpolation The "=" character has a special meaning at the start of an argument in Zsh. * Escape "{" and "}" for Zsh with interpolation Specifically in Zsh, "{" and "}" can be used for string expansion if there are no quotes. So, the err on the safe side, they will always be escaped when `interpolation` is true. * Fuzz `escape` function on PowerShell Run the fuzz target with the existing corpus on PowerShell and fix all problems that are uncovered. * Escape single quote variants in PowerShell on Windows Escape the following characters for PowerShell on Windows because it will interpret these as regular single quotes. - U+2018 (Left Single Quotation Mark) - U+2019 (Right Single Quotation Mark) - U+201B (Single High-Reversed-9 Quotation Mark) - U+201A (Single Low-9 Quotation Mark) * Escape "<" and ">" for Windows PowerShell with interpolation These characters have special meaning when they appear at the beginning of an argument. In the case of ">", it also has this meaning when it is prefixed by "1", "2", "3", "4", "5", "6", or "*". * Escape "@" for Windows PowerShell with interpolation This character has special meaning when it appears at the beginning of an argument. * Escape "]" for Windows PowerShell with interpolation This character has a special meaning when it appears at the beginning of an argument. * Escape "," for Windows PowerShell with interpolation This character is used to separate commands on PowerShell. * Escape leading "-" in PowerShell on Windows If "-" is the first character in an argument in PowerShell on Windows it has a special meaning, so it's always escaped. * Escape leading ":" in PowerShell on Windows If ":" is the first character in an argument in PowerShell on Windows it has a special meaning, so it's always escaped if it is the first character. * Fuzz `escape` function on cmd.exe Run the fuzz target with the existing corpus on cmd.exe and fix all problems that are uncovered. * Escape "^" for Windows cmd.exe with interpolation This character is used for escaping, so it must be escaped itself. As it is used for escaping, it should be escaped first to prevent escaping the "^" instances inserted to escape other characters. * Update unit test suites for changes to unix.js and win.js * Update unit test suites for changes to main.js * Update TypeScript type definitions * Update documentation for `escape` and `escapeAll` * Update CHANGELOG
- Loading branch information
1 parent
c0976d3
commit fcba4ee
Showing
38 changed files
with
3,312 additions
and
219 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
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
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
Binary file added
BIN
+16 Bytes
test/fuzz/corpus/109adf645551522f1b4ae343782eb8734ceddcaaea4ae5279a1c9bbd8599dbc3
Binary file not shown.
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/1e37238c1a5f6c736d4b8c23bfc2a79734e73379ecd7ae4b91b5c19b0bce54fb
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 @@ | ||
L:�\(;\ |
Binary file added
BIN
+23 Bytes
test/fuzz/corpus/21830eadbd638794eacc8fcc6e2561fcc80eb831461d55878365a462f3200f33
Binary file not shown.
Binary file added
BIN
+5 Bytes
test/fuzz/corpus/262ef9ba0ad8d7558feed09b6890d260f18f0aee5f75c55b030cbd1588e30041
Binary file not shown.
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/266755dd5469c485f454d8323853c5de1afc8237ad3148e87da136f57fe98817
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 @@ | ||
��$L:�> |
Binary file added
BIN
+24 Bytes
test/fuzz/corpus/34a5350b0725a631179b60adc4bbabd576bd4bf0e66b29d060a54708f088927e
Binary file not shown.
Binary file added
BIN
+10 Bytes
test/fuzz/corpus/38fcad1918902cf43fd0b4b5075beac8212600729df7fcf3678669ea16e5efe2
Binary file not shown.
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/3b60b38594678116b32f8ce69cc2adc067cf4cb47db7b0542807eb710e1b4382
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 @@ | ||
�G��Q�L:�\(?} |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/3ed325d1d68d7671458659f3ee7aa2f023ab307cb4c6b0a1a50970bc1cfa9ed4
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 @@ | ||
:X|]5 |
Binary file added
BIN
+4 Bytes
test/fuzz/corpus/6d3c3a670acc0f1c11c97805e4aad6c9d5a5223aae37f0fa25d8cc0482339f60
Binary file not shown.
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/720fb50e541a9b37787812a1aa27063f35abf5f0ad7a2b25226679955e24453b
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 @@ | ||
[9�\ |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/7ace431cb61584cb9b8dc7ec08cf38ac0a2d649660be86d349fb43108b542fa4
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 @@ | ||
~ |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/7af61f03a9bc5bac6b46555a60182ff1eb0ea509758aa0ce12611e7d629b2d8b
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 @@ | ||
@L:^�I�\(?\ |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/934fa52640ce75ee7ac58f1bf0772bc97735ae6d42ca5fc47173e5002b8f299a
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 @@ | ||
#��(�"�3Ww�� |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/958c9df7f1fc53b0ba36c3042b416e212c4f5a3c5b845d486d4fd9c306462bee
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 @@ | ||
!*(?\ ��\ |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/a95606bd226e5874b431b611f302846fe02611a0bc9d6b333bbdc4da6f4256e8
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 @@ | ||
package.j?on |
Binary file added
BIN
+23 Bytes
test/fuzz/corpus/bbdb728a2f5faaea7302082081e63c5ff130832767bf482b638b38195edec56b
Binary file not shown.
Binary file added
BIN
+8 Bytes
test/fuzz/corpus/c45811bde034f7ea476dabde191e6a633314f450fc697f7740bb607419f58fc7
Binary file not shown.
Binary file added
BIN
+15 Bytes
test/fuzz/corpus/c7bcdc8f379205c62e7e1e06b1de96fab9b2c2cea649510374be9d309ad63dbe
Binary file not shown.
Binary file added
BIN
+16 Bytes
test/fuzz/corpus/cacfe0fdeb3b9f6be474735b6881266da931367bdfe29406a7b9551e77a09340
Binary file not shown.
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/cdbcae15105d6b781e620813c79c7e868740d4e9cc53ce6f5fcbbc12387adf4b
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 @@ | ||
* |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/cfa73e24623488703e1e1a5f9002f63ba74d624cc22063ce60e4e586918079ee
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 @@ | ||
*>W�3w�3w�� |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/cfab074bdcae4ce4a18ea61959b5ce04024e7e31360b06324e263efd7af0e7e1
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 @@ | ||
p* |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/e87ed9941d75ac1b46da9d20915705a75e9f5ca6bed48123b2d46a0b80df7f2d
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 |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/e9ce945769b352dbf4550f08e15ac066e8ce84f2c2befbcbe8c5188888ca8e48
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 @@ | ||
L:�\(?\ |
1 change: 1 addition & 0 deletions
1
test/fuzz/corpus/fac29151619609f07c3b649a22c353abe89a6ea1709d7e79f27e62abad201e07
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 @@ | ||
@L:�\(?\ |
Oops, something went wrong.