Skip to content

Commit

Permalink
fix(parser): throw error on unterminated group expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
hugowetterberg committed Jan 8, 2015
1 parent 2be10ea commit 95c41d9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions index.js
Expand Up @@ -10,8 +10,9 @@ function Query(name, sql) {
this.queryObject = this.build(sql);
}

Query.prototype.build = function build(sql, start) {
Query.prototype.build = function build(sql, start, group) {
start = start || 0;

var query = {
query: [],
params: [],
Expand Down Expand Up @@ -52,7 +53,7 @@ Query.prototype.build = function build(sql, start) {
i+=2;
}

var group = build(sql, i);
var group = build(sql, i, true);

if (groupName) {
group.name = groupName;
Expand Down Expand Up @@ -100,6 +101,10 @@ Query.prototype.build = function build(sql, start) {
}
flush();

if (group && parens >= 0) {
throw new Error('Parse failed, unterminated group, expected ")" got end of string');
}

query.length = i-start;
return query;
};
Expand Down

0 comments on commit 95c41d9

Please sign in to comment.