colis-anr / morbig

A static parser for POSIX Shell
Other
190 stars 8 forks source link

In backquote subshells, double quotes seem to disappear #92

Closed Niols closed 5 years ago

Niols commented 5 years ago

Consider the script:

echo `echo "`

It's not clear to me whether this should be accepted (with the command echo " inside the subshell) or rejected (because of unterminated quotes). Dash rejects it complaining about unterminated quotes.

Morbig does accept it, but the double quotes seem to have disappeared. Whether it should be accepted or not, the output is wrong. Here is the simple json:

[
  "Command_SimpleCommand",
  [
    "SimpleCommand_CmdName_CmdSuffix",
    [
      "CmdName_Word",
      [ "Word", "echo", [ [ "WordName", "echo" ] ] ]
    ],
    [
      "CmdSuffix_Word",
      [
        "Word",
        "`echo \"`",
        [
          [
            "WordSubshell",
            [ "SubShellKindBackQuote" ],
            [
              "Program_LineBreak_CompleteCommands_LineBreak",
              [ "LineBreak_Empty" ],
              [
                "CompleteCommands_CompleteCommand",
                [
                  "CompleteCommand_CList",
                  [
                    "CList_AndOr",
                    [
                      "AndOr_Pipeline",
                      [
                        "Pipeline_PipeSequence",
                        [
                          "PipeSequence_Command",
                          [
                            "Command_SimpleCommand",
                            [
                              "SimpleCommand_CmdName",
                              [
                                "CmdName_Word",
                                [
                                  "Word",
                                  "echo",
                                  [ [ "WordName", "echo" ] ]
                                ]
                              ]
                            ]
                          ]
                        ]
                      ]
                    ]
                  ]
                ]
              ],
              [ "LineBreak_Empty" ]
            ]
          ]
        ]
      ]
    ]
  ]
]