Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8049300

jjs scripting: need way to quote $EXEC command arguments to protect spaces

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:

      Backports

        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.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  mhaupt Michael Haupt
                  Reporter:
                  smarks Stuart Marks
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: