fix #1820 ('foo (bar)' query becomes 'foo (0)')

This commit is contained in:
rlx 2013-08-26 15:21:02 +00:00
parent 3c0e7e7bf5
commit c1cf48852b

View file

@ -663,8 +663,12 @@ Ox.URL = function(options) {
function parseFind(str) {
str = (str || '').replace(/%7C/g, '|');
var conditions, counter = 0,
var counter = 0,
find = {conditions: [], operator: '&'},
salt = Ox.range(16).map(function() {
return Ox.char(65 + Ox.random(26));
}).join(''),
regexp = new RegExp(salt + '(\\d+)'),
subconditions = [];
if (str.length) {
// replace subconditions with placeholder,
@ -685,18 +689,16 @@ Ox.URL = function(options) {
return !!subcondition;
});
subconditions.forEach(function(subcondition, i) {
str = str.replace(subcondition, i);
str = str.replace(subcondition, salt + i);
});
find.operator = str.indexOf('|') > -1 ? '|' : '&'
find.conditions = str.split(find.operator).map(function(condition, i) {
var ret;
if (condition[0] == '(') {
// re-insert subcondition
ret = parseFind(subconditions[parseInt(condition.slice(1, -1))]);
} else {
ret = parseCondition(condition);
}
return ret;
condition = condition.replace(regexp, function(match) {
return subconditions[parseInt(arguments[1])];
});
return condition[0] == '('
? parseFind(condition.slice(1, -1))
: parseCondition(condition);
});
}
return find;