fix(parse): fix incorrect parse of heredocuments on broken lists
This commit is contained in:
parent
0d56e6099d
commit
d10be4116a
2 changed files with 30 additions and 22 deletions
|
|
@ -591,14 +591,14 @@ bool r_minify_single_block(_obj* in)
|
|||
if(ret != nullptr) {
|
||||
// concatenate redirects
|
||||
for(uint32_t j=0; j<t->cmds[i]->redirs.size(); j++)
|
||||
ret->redirs.insert(ret->redirs.begin()+j, t->cmds[i]->redirs[j]);
|
||||
ret->redirs.insert(ret->redirs.begin()+j, t->cmds[i]->redirs[j]);
|
||||
|
||||
// deindex
|
||||
t->cmds[i]->redirs.resize(0);
|
||||
if(t->cmds[i]->type == _obj::block_brace)
|
||||
dynamic_cast<brace_t*>(t->cmds[i])->lst->cls[0]->pls[0]->cmds[0] = nullptr;
|
||||
dynamic_cast<brace_t*>(t->cmds[i])->lst->cls[0]->pls[0]->cmds[0] = nullptr;
|
||||
else if(t->cmds[i]->type == _obj::block_subshell)
|
||||
dynamic_cast<subshell_t*>(t->cmds[i])->lst->cls[0]->pls[0]->cmds[0] = nullptr;
|
||||
dynamic_cast<subshell_t*>(t->cmds[i])->lst->cls[0]->pls[0]->cmds[0] = nullptr;
|
||||
|
||||
// replace value
|
||||
delete t->cmds[i];
|
||||
|
|
|
|||
|
|
@ -1085,27 +1085,35 @@ std::tuple<list_t*, parse_context, std::string> parse_list_until(parse_context c
|
|||
|
||||
if(ctx.here_document != nullptr)
|
||||
{
|
||||
uint8_t do_twice=2;
|
||||
// case of : cat << EOF ;
|
||||
while(do_twice>0)
|
||||
bool has_parsed=false;
|
||||
parse_context t_ctx=ctx;
|
||||
if(t_ctx[t_ctx.i] == '\n')
|
||||
{
|
||||
if(ctx[ctx.i] == '\n')
|
||||
{
|
||||
ctx = parse_heredocument(ctx+1);
|
||||
break;
|
||||
}
|
||||
else if(ctx[ctx.i] == '#')
|
||||
{
|
||||
ctx.i = skip_until(ctx, "\n"); //skip to endline
|
||||
ctx = parse_heredocument(ctx+1);
|
||||
break;
|
||||
}
|
||||
skip_chars(ctx, SPACES);
|
||||
do_twice--;
|
||||
t_ctx = parse_heredocument(t_ctx+1);
|
||||
has_parsed=true;
|
||||
}
|
||||
// case of : cat << EOF ; ;
|
||||
if(do_twice==0 && is_in(ctx[ctx.i], COMMAND_SEPARATOR))
|
||||
parse_error( unexpected_token(ctx[ctx.i]), ctx);
|
||||
else if(t_ctx[t_ctx.i] == '#')
|
||||
{
|
||||
t_ctx.i = skip_until(t_ctx, "\n"); //skip to endline
|
||||
t_ctx = parse_heredocument(t_ctx+1);
|
||||
has_parsed=true;
|
||||
}
|
||||
else if(t_ctx[t_ctx.i] == ';') {
|
||||
t_ctx.i = skip_chars(t_ctx+1, SPACES);
|
||||
if(t_ctx[t_ctx.i] == '\n')
|
||||
{
|
||||
t_ctx = parse_heredocument(t_ctx+1);
|
||||
has_parsed=true;
|
||||
}
|
||||
else if(t_ctx[t_ctx.i] == '#')
|
||||
{
|
||||
t_ctx.i = skip_until(t_ctx, "\n"); //skip to endline
|
||||
t_ctx = parse_heredocument(t_ctx+1);
|
||||
has_parsed=true;
|
||||
}
|
||||
}
|
||||
if(has_parsed)
|
||||
ctx = t_ctx;
|
||||
}
|
||||
|
||||
if(is_in(ctx[ctx.i], COMMAND_SEPARATOR))
|
||||
|
|
|
|||
Loading…
Reference in a new issue