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
|
|
@ -1085,27 +1085,35 @@ std::tuple<list_t*, parse_context, std::string> parse_list_until(parse_context c
|
||||||
|
|
||||||
if(ctx.here_document != nullptr)
|
if(ctx.here_document != nullptr)
|
||||||
{
|
{
|
||||||
uint8_t do_twice=2;
|
bool has_parsed=false;
|
||||||
// case of : cat << EOF ;
|
parse_context t_ctx=ctx;
|
||||||
while(do_twice>0)
|
if(t_ctx[t_ctx.i] == '\n')
|
||||||
{
|
{
|
||||||
if(ctx[ctx.i] == '\n')
|
t_ctx = parse_heredocument(t_ctx+1);
|
||||||
|
has_parsed=true;
|
||||||
|
}
|
||||||
|
else if(t_ctx[t_ctx.i] == '#')
|
||||||
{
|
{
|
||||||
ctx = parse_heredocument(ctx+1);
|
t_ctx.i = skip_until(t_ctx, "\n"); //skip to endline
|
||||||
break;
|
t_ctx = parse_heredocument(t_ctx+1);
|
||||||
|
has_parsed=true;
|
||||||
}
|
}
|
||||||
else if(ctx[ctx.i] == '#')
|
else if(t_ctx[t_ctx.i] == ';') {
|
||||||
|
t_ctx.i = skip_chars(t_ctx+1, SPACES);
|
||||||
|
if(t_ctx[t_ctx.i] == '\n')
|
||||||
{
|
{
|
||||||
ctx.i = skip_until(ctx, "\n"); //skip to endline
|
t_ctx = parse_heredocument(t_ctx+1);
|
||||||
ctx = parse_heredocument(ctx+1);
|
has_parsed=true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
skip_chars(ctx, SPACES);
|
else if(t_ctx[t_ctx.i] == '#')
|
||||||
do_twice--;
|
{
|
||||||
|
t_ctx.i = skip_until(t_ctx, "\n"); //skip to endline
|
||||||
|
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))
|
if(has_parsed)
|
||||||
parse_error( unexpected_token(ctx[ctx.i]), ctx);
|
ctx = t_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_in(ctx[ctx.i], COMMAND_SEPARATOR))
|
if(is_in(ctx[ctx.i], COMMAND_SEPARATOR))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue