Commit 8fefed0

Anton Medvedev <anton@medv.io>
2021-08-13 02:51:58
Fix quote and substitute bugs
1 parent bb9cf38
Changed files (3)
examples/basics.mjs
@@ -16,12 +16,6 @@
 
 await $`ls -1 | wc -l`
 
-await Promise.all([
-  $`sleep 1; echo 1`,
-  $`sleep 2; echo 2`,
-  $`sleep 3; echo 3`,
-])
-
 let branch = await $`git branch --show-current`
 await $`printf ${branch} | wc` // The new line trimmed from stdout.
 
index.mjs
@@ -239,11 +239,11 @@ function substitute(arg) {
   if (arg instanceof ProcessOutput) {
     return arg.stdout.replace(/\n$/, '')
   }
-  return arg.toString()
+  return `${arg}`
 }
 
 function quote(arg) {
-  if (/^[a-z0-9/_.-]+$/i.test(arg)) {
+  if (/^[a-z0-9/_.-]+$/i.test(arg) || arg === '') {
     return arg
   }
   return `$'`
test.mjs
@@ -32,6 +32,11 @@ import path from 'path'
   assert((await $`echo ${bar}`).stdout.trim() === bar)
 }
 
+{ // Undefined and empty string correctly quoted
+  $`echo ${undefined}`
+  $`echo ${''}`
+}
+
 { // Can create a dir with a space in the name
   let name = 'foo bar'
   try {