UI for Zipcoin Blue

escapeArgument.js 875B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. function escapeArgument(arg, quote) {
  3. // Convert to string
  4. arg = '' + arg;
  5. // If we are not going to quote the argument,
  6. // escape shell metacharacters, including double and single quotes:
  7. if (!quote) {
  8. arg = arg.replace(/([()%!^<>&|;,"'\s])/g, '^$1');
  9. } else {
  10. // Sequence of backslashes followed by a double quote:
  11. // double up all the backslashes and escape the double quote
  12. arg = arg.replace(/(\\*)"/g, '$1$1\\"');
  13. // Sequence of backslashes followed by the end of the string
  14. // (which will become a double quote later):
  15. // double up all the backslashes
  16. arg = arg.replace(/(\\*)$/, '$1$1');
  17. // All other backslashes occur literally
  18. // Quote the whole thing:
  19. arg = '"' + arg + '"';
  20. }
  21. return arg;
  22. }
  23. module.exports = escapeArgument;