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