diff options
author | AndrewCEmil <andrew.emil@10gen.com> | 2013-03-13 15:24:07 -0700 |
---|---|---|
committer | AndrewCEmil <andrew.emil@10gen.com> | 2013-03-20 17:21:20 -0700 |
commit | ec757744090ebeac463fdf2ba6ea5e4c9e27851f (patch) | |
tree | d2605653bdb115adb679e6fd8f338ff89c431215 /src/mongo/scripting | |
parent | 59a863f82956e070331b7262070d3ef7de4324c5 (diff) | |
download | mongo-ec757744090ebeac463fdf2ba6ea5e4c9e27851f.tar.gz |
SERVER-5689, fix and associated tests
Diffstat (limited to 'src/mongo/scripting')
-rw-r--r-- | src/mongo/scripting/engine.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/mongo/scripting/engine.cpp b/src/mongo/scripting/engine.cpp index 9538e7186f3..b110c624823 100644 --- a/src/mongo/scripting/engine.cpp +++ b/src/mongo/scripting/engine.cpp @@ -443,8 +443,24 @@ namespace mongo { if (x == string::npos) return false; - return (x == 0 || !isalpha(code[x-1])) && - !isalpha(code[x+6]); + int quoteCount = 0; + int singleQuoteCount = 0; + for (size_t i = 0; i < x; i++) { + if (code[i] == '"') { + quoteCount++; + } else if(code[i] == '\'') { + singleQuoteCount++; + } + } + // if we are in either single quotes or double quotes return false + if (quoteCount % 2 != 0 || singleQuoteCount % 2 != 0) { + return false; + } + + // return is at start OR preceded by space + // AND return is not followed by digit or letter + return (x == 0 || isspace(code[x-1])) && + !(isalpha(code[x+6]) || isdigit(code[x+6])); } const char* jsSkipWhiteSpace(const char* raw) { |