| 96 | }; |
| 97 | |
| 98 | var parseObject = function (chain, val, options) { |
| 99 | var leaf = val; |
| 100 | |
| 101 | for (var i = chain.length - 1; i >= 0; --i) { |
| 102 | var obj; |
| 103 | var root = chain[i]; |
| 104 | |
| 105 | if (root === '[]' && options.parseArrays) { |
| 106 | obj = [].concat(leaf); |
| 107 | } else { |
| 108 | obj = options.plainObjects ? Object.create(null) : {}; |
| 109 | var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root; |
| 110 | var index = parseInt(cleanRoot, 10); |
| 111 | if (!options.parseArrays && cleanRoot === '') { |
| 112 | obj = { 0: leaf }; |
| 113 | } else if ( |
| 114 | !isNaN(index) |
| 115 | && root !== cleanRoot |
| 116 | && String(index) === cleanRoot |
| 117 | && index >= 0 |
| 118 | && (options.parseArrays && index <= options.arrayLimit) |
| 119 | ) { |
| 120 | obj = []; |
| 121 | obj[index] = leaf; |
| 122 | } else { |
| 123 | obj[cleanRoot] = leaf; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | leaf = obj; |
| 128 | } |
| 129 | |
| 130 | return leaf; |
| 131 | }; |
| 132 | |
| 133 | var parseKeys = function parseQueryStringKeys(givenKey, val, options) { |
| 134 | if (!givenKey) { |