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

test

parent 343da0a9
Loading
Loading
Loading
Loading
+29 −14
Changes for src/shell.cpp: 29 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -144,6 +144,21 @@ static size_t cmdSubstClose(const std::string &s,size_t from){
    return n;
}


// The closing '"' of a double-quoted string whose text starts at `from`
// (s.size() if unterminated): escapes, "$(...)" (its own quoting
// context) and backquoted commands inside are skipped.
static size_t dqEnd(const std::string &s,size_t from){
    size_t n=s.size(),i=from;
    while(i<n && s[i]!='"'){
        if(s[i]=='\\' && i+1<n){ i+=2; continue; }
        if(s[i]=='$' && i+1<n && s[i+1]=='('){ size_t c=cmdSubstClose(s,i+2); i=(c<n) ? c+1 : n; continue; }
        if(s[i]=='`'){ ++i; while(i<n && s[i]!='`'){ if(s[i]=='\\') ++i; ++i; } if(i<n) ++i; continue; }
        ++i;
    }
    return i;
}

static void pushGlobExpanded(std::vector<std::string> &tokens,const std::string &word){
    if(word.find_first_of("*?[")==std::string::npos){
        tokens.push_back(word);
@@ -1996,10 +2011,10 @@ std::vector<std::string> fresh::splitPipelineStages(const std::string &segment,
            char q=c;
            current+=c;
            ++i;
            while(i<n && segment[i]!=q){
                current+=segment[i];
                ++i;
            }
            size_t e=(q=='"') ? dqEnd(segment,i) : segment.find(q,i);
            if(e==std::string::npos) e=n;
            current.append(segment,i,e-i);
            i=e;
            if(i<n){
                current+=segment[i];
                ++i;
@@ -2217,14 +2232,7 @@ bool fresh::extractBraceGroupBody(const std::string &stage,std::string &body,std
            char q=c;
            ++j;
            if(q=='"'){
                while(j<n && stage[j]!=q){
                    if(stage[j]=='\\' && j+1<n &&
                       (stage[j+1]=='"' || stage[j+1]=='\\' ||
                        stage[j+1]=='$' || stage[j+1]=='`'))
                        j+=2;
                    else
                        ++j;
                }
                j=dqEnd(stage,j);
            }else{
                while(j<n && stage[j]!=q)
                    ++j;
@@ -2420,6 +2428,13 @@ bool fresh::needsMoreInput(const std::string &text){
                i+=2;
                continue;
            }
            // "$(...)" inside double quotes: its quotes are its own
            if(quoteState=='"' && c=='$' && i+1<n && text[i+1]=='('){
                size_t close=cmdSubstClose(text,i+2);
                if(close>=n) return true;
                i=close+1;
                continue;
            }
            if(c==quoteState) quoteState=0;
            ++i;
            continue;
@@ -2678,8 +2693,8 @@ bool fresh::extractHeredocSpec(std::string &text,fresh::HeredocSpec &spec){
        if(c=='\'' || c=='"'){
            char q=c;
            ++i;
            while(i<n && text[i]!=q)
                ++i;
            if(q=='"') i=dqEnd(text,i);
            else while(i<n && text[i]!=q) ++i;
            if(i<n)
                ++i;
            continue;