Commit ab1fc1c6 authored by jan.koester's avatar jan.koester
Browse files

heredoc fixed

parent 32d0e206
Loading
Loading
Loading
Loading
+18 −0
Changes for src/shell.cpp: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2974,6 +2974,24 @@ bool fresh::extractHeredocSpec(std::string &text,fresh::HeredocSpec &spec){
    while(i<n){
        char c=text[i];

        // A "<<WORD" inside "$(...)" or `...` belongs to that inner
        // command (runCaptured() parses it, body included) -- taking it as
        // this command's own heredoc stripped the marker out of the
        // substitution and read the body from the script instead:
        // v=$(cat <<EOF ... EOF) came out empty and desynced the rest of
        // the script.
        if(c=='$' && i+1<n && text[i+1]=='(' && !(i+2<n && text[i+2]=='(')){
            size_t close=cmdSubstClose(text,i+2);
            i=(close<n) ? close+1 : n;
            continue;
        }
        if(c=='`'){
            ++i;
            while(i<n && text[i]!='`'){ if(text[i]=='\\') ++i; ++i; }
            if(i<n) ++i;
            continue;
        }

        if(c=='\'' || c=='"'){
            char q=c;
            ++i;