JDK-8049300 : jjs scripting: need way to quote $EXEC command arguments to protect spaces
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-07-03
  • Updated: 2015-09-29
  • Resolved: 2015-05-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b66Fixed
Related Reports
Relates :  
Description
The $EXEC and `command` facilities of Nashorn scripting unconditionally break the string into words using StringTokenizer. There is no way to protect spaces from causing word breaks; there needs to be. The usual way to do this is to provide an alternative form of executing a command that takes an array of strings and passes it directly to ProcessBuilder, instead of tokenizing a single string into an array before passing it to ProcessBuilder.

In addition, the tokenizing behavior is overly simplistic. It would also be nice to have another command that passes a single string as the argument to sh -c. (Where "sh" would be replaced by the value of the SHELL environment variable.) This would allow for proper shell-style quoting and redirection.

===== CURRENT BEHAVIOR =====

sh-3.2$ ls
sh-3.2$ touch a 'b c'
sh-3.2$ ls -l
total 0
-rw-rw-r--+ 1 smarks  smarks  0 Jul  3 14:59 a
-rw-rw-r--+ 1 smarks  smarks  0 Jul  3 14:59 b c
sh-3.2$ jjs -scripting
jjs> $EXEC("ls -l")
total 0
-rw-rw-r--+ 1 smarks  smarks  0 Jul  3 14:59 a
-rw-rw-r--+ 1 smarks  smarks  0 Jul  3 14:59 b c

jjs> $EXEC("ls -l a")
-rw-rw-r--+ 1 smarks  smarks  0 Jul  3 14:59 a

jjs> $EXEC("ls -l 'b c'")

jjs> $ERR
ls: 'b: No such file or directory
ls: c': No such file or directory

jjs> $EXEC("ls -l b\ c")

jjs> $ERR
ls: b: No such file or directory
ls: c: No such file or directory

===== DESIRED BEHAVIOR =====

jjs> $EXECV("ls", "-l", "a", "b c")
-rw-rw-r--+ 1 smarks  smarks  0 Jul  3 14:59 a
-rw-rw-r--+ 1 smarks  smarks  0 Jul  3 14:59 b c

jjs> $RUN("ls -l a 'b c' | wc")
       2      19      96

=====

It doesn't have to be exactly the above, of course. Some means will need to be provided for passing data to stdin much like $EXEC does today.