Skip to content

Instantly share code, notes, and snippets.

View shanesmith's full-sized avatar
🤨

Shane Smith shanesmith

🤨
  • Clio
  • Ottawa, ON
View GitHub Profile
@creationix
creationix / bash-escape.js
Created April 26, 2012 20:08
Bash argument escaping
// Implement bash string escaping.
var safePattern = /^[a-z0-9_\/\-.,?:@#%^+=\[\]]*$/i;
var safeishPattern = /^[a-z0-9_\/\-.,?:@#%^+=\[\]{}|&()<>; *']*$/i;
function bashEscape(arg) {
// These don't need quoting
if (safePattern.test(arg)) return arg;
// These are fine wrapped in double quotes using weak escaping.
if (safeishPattern.test(arg)) return '"' + arg + '"';