mirror of
https://github.com/sstent/expressmongotest.git
synced 2026-01-25 16:42:00 +00:00
added article
This commit is contained in:
@@ -39,7 +39,7 @@ app.configure('production', function(){
|
||||
require('./routes/index')(app);
|
||||
require('./routes/users')(app);
|
||||
require('./routes/session')(app);
|
||||
|
||||
require('./routes/articles')(app);
|
||||
|
||||
app.listen(3000, function(){
|
||||
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
|
||||
|
||||
6
test/data/models/article.js
Normal file
6
test/data/models/article.js
Normal file
@@ -0,0 +1,6 @@
|
||||
var mongoose = require('mongoose');
|
||||
var ArticleSchema = require('../schemas/article');
|
||||
|
||||
var Article = mongoose.model('Article', ArticleSchema);
|
||||
|
||||
module.exports = Article;
|
||||
20
test/data/schemas/article.js
Normal file
20
test/data/schemas/article.js
Normal file
@@ -0,0 +1,20 @@
|
||||
var Schema = require('mongoose').Schema;
|
||||
|
||||
var ArticleSchema = new Schema({
|
||||
title: {
|
||||
type: String,
|
||||
unique: true
|
||||
},
|
||||
body: String,
|
||||
author: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'User',
|
||||
required: true
|
||||
},
|
||||
created_at: {
|
||||
type: Date,
|
||||
'default': Date.now
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ArticleSchema;
|
||||
17
test/data/schemas/user.js
Normal file
17
test/data/schemas/user.js
Normal file
@@ -0,0 +1,17 @@
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
var UserSchema = new mongoose.Schema({
|
||||
username: {type: String, unique: true},
|
||||
name: String,
|
||||
password: String,
|
||||
});
|
||||
|
||||
UserSchema.methods.recentArticles = function(callback) {
|
||||
return this.model('Article')
|
||||
.find({author: this._id})
|
||||
//.sort('created_at', 1)
|
||||
.limit(5)
|
||||
.exec(callback);
|
||||
};
|
||||
|
||||
module.exports = UserSchema;
|
||||
6
test/node_modules/qs/.gitmodules
generated
vendored
Normal file
6
test/node_modules/qs/.gitmodules
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[submodule "support/expresso"]
|
||||
path = support/expresso
|
||||
url = git://github.com/visionmedia/expresso.git
|
||||
[submodule "support/should"]
|
||||
path = support/should
|
||||
url = git://github.com/visionmedia/should.js.git
|
||||
1
test/node_modules/qs/.npmignore
generated
vendored
Normal file
1
test/node_modules/qs/.npmignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
4
test/node_modules/qs/.travis.yml
generated
vendored
Normal file
4
test/node_modules/qs/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.6
|
||||
- 0.4
|
||||
94
test/node_modules/qs/History.md
generated
vendored
Normal file
94
test/node_modules/qs/History.md
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
|
||||
0.5.3 2012-12-09
|
||||
==================
|
||||
|
||||
* add info to component.json
|
||||
* remove regular client-side ./querystring.js, fix component.json support
|
||||
|
||||
0.5.2 / 2012-11-14
|
||||
==================
|
||||
|
||||
* fix uri encoding of non-plain object string values
|
||||
|
||||
0.5.1 / 2012-09-18
|
||||
==================
|
||||
|
||||
* fix encoded `=`. Closes #43
|
||||
|
||||
0.5.0 / 2012-05-04
|
||||
==================
|
||||
|
||||
* Added component support
|
||||
|
||||
0.4.2 / 2012-02-08
|
||||
==================
|
||||
|
||||
* Fixed: ensure objects are created when appropriate not arrays [aheckmann]
|
||||
|
||||
0.4.1 / 2012-01-26
|
||||
==================
|
||||
|
||||
* Fixed stringify()ing numbers. Closes #23
|
||||
|
||||
0.4.0 / 2011-11-21
|
||||
==================
|
||||
|
||||
* Allow parsing of an existing object (for `bodyParser()`) [jackyz]
|
||||
* Replaced expresso with mocha
|
||||
|
||||
0.3.2 / 2011-11-08
|
||||
==================
|
||||
|
||||
* Fixed global variable leak
|
||||
|
||||
0.3.1 / 2011-08-17
|
||||
==================
|
||||
|
||||
* Added `try/catch` around malformed uri components
|
||||
* Add test coverage for Array native method bleed-though
|
||||
|
||||
0.3.0 / 2011-07-19
|
||||
==================
|
||||
|
||||
* Allow `array[index]` and `object[property]` syntaxes [Aria Stewart]
|
||||
|
||||
0.2.0 / 2011-06-29
|
||||
==================
|
||||
|
||||
* Added `qs.stringify()` [Cory Forsyth]
|
||||
|
||||
0.1.0 / 2011-04-13
|
||||
==================
|
||||
|
||||
* Added jQuery-ish array support
|
||||
|
||||
0.0.7 / 2011-03-13
|
||||
==================
|
||||
|
||||
* Fixed; handle empty string and `== null` in `qs.parse()` [dmit]
|
||||
allows for convenient `qs.parse(url.parse(str).query)`
|
||||
|
||||
0.0.6 / 2011-02-14
|
||||
==================
|
||||
|
||||
* Fixed; support for implicit arrays
|
||||
|
||||
0.0.4 / 2011-02-09
|
||||
==================
|
||||
|
||||
* Fixed `+` as a space
|
||||
|
||||
0.0.3 / 2011-02-08
|
||||
==================
|
||||
|
||||
* Fixed case when right-hand value contains "]"
|
||||
|
||||
0.0.2 / 2011-02-07
|
||||
==================
|
||||
|
||||
* Fixed "=" presence in key
|
||||
|
||||
0.0.1 / 2011-02-07
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
6
test/node_modules/qs/Makefile
generated
vendored
Normal file
6
test/node_modules/qs/Makefile
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
test:
|
||||
@./node_modules/.bin/mocha \
|
||||
--ui bdd
|
||||
|
||||
.PHONY: test
|
||||
58
test/node_modules/qs/Readme.md
generated
vendored
Normal file
58
test/node_modules/qs/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
# node-querystring
|
||||
|
||||
query string parser for node and the browser supporting nesting, as it was removed from `0.3.x`, so this library provides the previous and commonly desired behaviour (and twice as fast). Used by [express](http://expressjs.com), [connect](http://senchalabs.github.com/connect) and others.
|
||||
|
||||
## Installation
|
||||
|
||||
$ npm install qs
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
var qs = require('qs');
|
||||
|
||||
qs.parse('user[name][first]=Tobi&user[email]=tobi@learnboost.com');
|
||||
// => { user: { name: { first: 'Tobi' }, email: 'tobi@learnboost.com' } }
|
||||
|
||||
qs.stringify({ user: { name: 'Tobi', email: 'tobi@learnboost.com' }})
|
||||
// => user[name]=Tobi&user[email]=tobi%40learnboost.com
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
Install dev dependencies:
|
||||
|
||||
$ npm install -d
|
||||
|
||||
and execute:
|
||||
|
||||
$ make test
|
||||
|
||||
browser:
|
||||
|
||||
$ open test/browser/index.html
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
17
test/node_modules/qs/benchmark.js
generated
vendored
Normal file
17
test/node_modules/qs/benchmark.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
var qs = require('./');
|
||||
|
||||
var times = 100000
|
||||
, start = new Date
|
||||
, n = times;
|
||||
|
||||
console.log('times: %d', times);
|
||||
|
||||
while (n--) qs.parse('foo=bar');
|
||||
console.log('simple: %dms', new Date - start);
|
||||
|
||||
var start = new Date
|
||||
, n = times;
|
||||
|
||||
while (n--) qs.parse('user[name][first]=tj&user[name][last]=holowaychuk');
|
||||
console.log('nested: %dms', new Date - start);
|
||||
9
test/node_modules/qs/component.json
generated
vendored
Normal file
9
test/node_modules/qs/component.json
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "querystring",
|
||||
"repo": "visionmedia/node-querystring",
|
||||
"description": "query-string parser / stringifier with nesting support",
|
||||
"version": "0.5.3",
|
||||
"keywords": ["querystring", "query", "parser"],
|
||||
"scripts": ["index.js"],
|
||||
"license": "MIT"
|
||||
}
|
||||
51
test/node_modules/qs/examples.js
generated
vendored
Normal file
51
test/node_modules/qs/examples.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var qs = require('./');
|
||||
|
||||
var obj = qs.parse('foo');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('foo=bar=baz');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('users[]');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('name=tj&email=tj@vision-media.ca');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('users[]=tj&users[]=tobi&users[]=jane');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('user[name][first]=tj&user[name][last]=holowaychuk');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('users[][name][first]=tj&users[][name][last]=holowaychuk');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('a=a&a=b&a=c');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('user[tj]=tj&user[tj]=TJ');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('user[names]=tj&user[names]=TJ&user[names]=Tyler');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('user[name][first]=tj&user[name][first]=TJ');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('user[0]=tj&user[1]=TJ');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('user[0]=tj&user[]=TJ');
|
||||
console.log(obj)
|
||||
|
||||
var obj = qs.parse('user[0]=tj&user[foo]=TJ');
|
||||
console.log(obj)
|
||||
|
||||
var str = qs.stringify({ user: { name: 'Tobi', email: 'tobi@learnboost.com' }});
|
||||
console.log(str);
|
||||
262
test/node_modules/qs/index.js
generated
vendored
Normal file
262
test/node_modules/qs/index.js
generated
vendored
Normal file
@@ -0,0 +1,262 @@
|
||||
|
||||
/**
|
||||
* Object#toString() ref for stringify().
|
||||
*/
|
||||
|
||||
var toString = Object.prototype.toString;
|
||||
|
||||
/**
|
||||
* Cache non-integer test regexp.
|
||||
*/
|
||||
|
||||
var isint = /^[0-9]+$/;
|
||||
|
||||
function promote(parent, key) {
|
||||
if (parent[key].length == 0) return parent[key] = {};
|
||||
var t = {};
|
||||
for (var i in parent[key]) t[i] = parent[key][i];
|
||||
parent[key] = t;
|
||||
return t;
|
||||
}
|
||||
|
||||
function parse(parts, parent, key, val) {
|
||||
var part = parts.shift();
|
||||
// end
|
||||
if (!part) {
|
||||
if (Array.isArray(parent[key])) {
|
||||
parent[key].push(val);
|
||||
} else if ('object' == typeof parent[key]) {
|
||||
parent[key] = val;
|
||||
} else if ('undefined' == typeof parent[key]) {
|
||||
parent[key] = val;
|
||||
} else {
|
||||
parent[key] = [parent[key], val];
|
||||
}
|
||||
// array
|
||||
} else {
|
||||
var obj = parent[key] = parent[key] || [];
|
||||
if (']' == part) {
|
||||
if (Array.isArray(obj)) {
|
||||
if ('' != val) obj.push(val);
|
||||
} else if ('object' == typeof obj) {
|
||||
obj[Object.keys(obj).length] = val;
|
||||
} else {
|
||||
obj = parent[key] = [parent[key], val];
|
||||
}
|
||||
// prop
|
||||
} else if (~part.indexOf(']')) {
|
||||
part = part.substr(0, part.length - 1);
|
||||
if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
|
||||
parse(parts, obj, part, val);
|
||||
// key
|
||||
} else {
|
||||
if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
|
||||
parse(parts, obj, part, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge parent key/val pair.
|
||||
*/
|
||||
|
||||
function merge(parent, key, val){
|
||||
if (~key.indexOf(']')) {
|
||||
var parts = key.split('[')
|
||||
, len = parts.length
|
||||
, last = len - 1;
|
||||
parse(parts, parent, 'base', val);
|
||||
// optimize
|
||||
} else {
|
||||
if (!isint.test(key) && Array.isArray(parent.base)) {
|
||||
var t = {};
|
||||
for (var k in parent.base) t[k] = parent.base[k];
|
||||
parent.base = t;
|
||||
}
|
||||
set(parent.base, key, val);
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given obj.
|
||||
*/
|
||||
|
||||
function parseObject(obj){
|
||||
var ret = { base: {} };
|
||||
Object.keys(obj).forEach(function(name){
|
||||
merge(ret, name, obj[name]);
|
||||
});
|
||||
return ret.base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given str.
|
||||
*/
|
||||
|
||||
function parseString(str){
|
||||
return String(str)
|
||||
.split('&')
|
||||
.reduce(function(ret, pair){
|
||||
var eql = pair.indexOf('=')
|
||||
, brace = lastBraceInKey(pair)
|
||||
, key = pair.substr(0, brace || eql)
|
||||
, val = pair.substr(brace || eql, pair.length)
|
||||
, val = val.substr(val.indexOf('=') + 1, val.length);
|
||||
|
||||
// ?foo
|
||||
if ('' == key) key = pair, val = '';
|
||||
|
||||
return merge(ret, decode(key), decode(val));
|
||||
}, { base: {} }).base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given query `str` or `obj`, returning an object.
|
||||
*
|
||||
* @param {String} str | {Object} obj
|
||||
* @return {Object}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.parse = function(str){
|
||||
if (null == str || '' == str) return {};
|
||||
return 'object' == typeof str
|
||||
? parseObject(str)
|
||||
: parseString(str);
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn the given `obj` into a query string
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
var stringify = exports.stringify = function(obj, prefix) {
|
||||
if (Array.isArray(obj)) {
|
||||
return stringifyArray(obj, prefix);
|
||||
} else if ('[object Object]' == toString.call(obj)) {
|
||||
return stringifyObject(obj, prefix);
|
||||
} else if ('string' == typeof obj) {
|
||||
return stringifyString(obj, prefix);
|
||||
} else {
|
||||
return prefix + '=' + encodeURIComponent(String(obj));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stringify the given `str`.
|
||||
*
|
||||
* @param {String} str
|
||||
* @param {String} prefix
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function stringifyString(str, prefix) {
|
||||
if (!prefix) throw new TypeError('stringify expects an object');
|
||||
return prefix + '=' + encodeURIComponent(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify the given `arr`.
|
||||
*
|
||||
* @param {Array} arr
|
||||
* @param {String} prefix
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function stringifyArray(arr, prefix) {
|
||||
var ret = [];
|
||||
if (!prefix) throw new TypeError('stringify expects an object');
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
ret.push(stringify(arr[i], prefix + '[' + i + ']'));
|
||||
}
|
||||
return ret.join('&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify the given `obj`.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @param {String} prefix
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function stringifyObject(obj, prefix) {
|
||||
var ret = []
|
||||
, keys = Object.keys(obj)
|
||||
, key;
|
||||
|
||||
for (var i = 0, len = keys.length; i < len; ++i) {
|
||||
key = keys[i];
|
||||
ret.push(stringify(obj[key], prefix
|
||||
? prefix + '[' + encodeURIComponent(key) + ']'
|
||||
: encodeURIComponent(key)));
|
||||
}
|
||||
|
||||
return ret.join('&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set `obj`'s `key` to `val` respecting
|
||||
* the weird and wonderful syntax of a qs,
|
||||
* where "foo=bar&foo=baz" becomes an array.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @param {String} key
|
||||
* @param {String} val
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function set(obj, key, val) {
|
||||
var v = obj[key];
|
||||
if (undefined === v) {
|
||||
obj[key] = val;
|
||||
} else if (Array.isArray(v)) {
|
||||
v.push(val);
|
||||
} else {
|
||||
obj[key] = [v, val];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate last brace in `str` within the key.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function lastBraceInKey(str) {
|
||||
var len = str.length
|
||||
, brace
|
||||
, c;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
c = str[i];
|
||||
if (']' == c) brace = false;
|
||||
if ('[' == c) brace = true;
|
||||
if ('=' == c && !brace) return i;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode `str`.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function decode(str) {
|
||||
try {
|
||||
return decodeURIComponent(str.replace(/\+/g, ' '));
|
||||
} catch (err) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
39
test/node_modules/qs/package.json
generated
vendored
Normal file
39
test/node_modules/qs/package.json
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "qs",
|
||||
"description": "querystring parser",
|
||||
"version": "0.5.3",
|
||||
"keywords": [
|
||||
"query string",
|
||||
"parser",
|
||||
"component"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/visionmedia/node-querystring.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "*",
|
||||
"expect.js": "*"
|
||||
},
|
||||
"component": {
|
||||
"scripts": {
|
||||
"querystring": "querystring.js"
|
||||
}
|
||||
},
|
||||
"author": {
|
||||
"name": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca",
|
||||
"url": "http://tjholowaychuk.com"
|
||||
},
|
||||
"main": "index",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"readme": "# node-querystring\n\n query string parser for node and the browser supporting nesting, as it was removed from `0.3.x`, so this library provides the previous and commonly desired behaviour (and twice as fast). Used by [express](http://expressjs.com), [connect](http://senchalabs.github.com/connect) and others.\n\n## Installation\n\n $ npm install qs\n\n## Examples\n\n```js\nvar qs = require('qs');\n\nqs.parse('user[name][first]=Tobi&user[email]=tobi@learnboost.com');\n// => { user: { name: { first: 'Tobi' }, email: 'tobi@learnboost.com' } }\n\nqs.stringify({ user: { name: 'Tobi', email: 'tobi@learnboost.com' }})\n// => user[name]=Tobi&user[email]=tobi%40learnboost.com\n```\n\n## Testing\n\nInstall dev dependencies:\n\n $ npm install -d\n\nand execute:\n\n $ make test\n\nbrowser:\n\n $ open test/browser/index.html\n\n## License \n\n(The MIT License)\n\nCopyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca>\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
|
||||
"readmeFilename": "Readme.md",
|
||||
"_id": "qs@0.5.3",
|
||||
"dist": {
|
||||
"shasum": "40699a6db18d60119127d6ec666b855c61c3bb5f"
|
||||
},
|
||||
"_from": "qs"
|
||||
}
|
||||
1202
test/node_modules/qs/test/browser/expect.js
generated
vendored
Normal file
1202
test/node_modules/qs/test/browser/expect.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
18
test/node_modules/qs/test/browser/index.html
generated
vendored
Normal file
18
test/node_modules/qs/test/browser/index.html
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Mocha</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<link rel="stylesheet" href="mocha.css" />
|
||||
<script src="jquery.js" type="text/javascript"></script>
|
||||
<script src="expect.js"></script>
|
||||
<script src="mocha.js"></script>
|
||||
<script>mocha.setup('bdd')</script>
|
||||
<script src="qs.js"></script>
|
||||
<script src="../parse.js"></script>
|
||||
<script src="../stringify.js"></script>
|
||||
<script>onload = mocha.run;</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
</body>
|
||||
</html>
|
||||
8981
test/node_modules/qs/test/browser/jquery.js
generated
vendored
Normal file
8981
test/node_modules/qs/test/browser/jquery.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
163
test/node_modules/qs/test/browser/mocha.css
generated
vendored
Normal file
163
test/node_modules/qs/test/browser/mocha.css
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
|
||||
body {
|
||||
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
padding: 60px 50px;
|
||||
}
|
||||
|
||||
#mocha h1, h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#mocha h1 {
|
||||
margin-top: 15px;
|
||||
font-size: 1em;
|
||||
font-weight: 200;
|
||||
}
|
||||
|
||||
#mocha .suite .suite h1 {
|
||||
margin-top: 0;
|
||||
font-size: .8em;
|
||||
}
|
||||
|
||||
#mocha h2 {
|
||||
font-size: 12px;
|
||||
font-weight: normal;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#mocha .suite {
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
#mocha .test {
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
#mocha .test:hover h2::after {
|
||||
position: relative;
|
||||
top: 0;
|
||||
right: -10px;
|
||||
content: '(view source)';
|
||||
font-size: 12px;
|
||||
font-family: arial;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
#mocha .test.pending:hover h2::after {
|
||||
content: '(pending)';
|
||||
font-family: arial;
|
||||
}
|
||||
|
||||
#mocha .test.pass.medium .duration {
|
||||
background: #C09853;
|
||||
}
|
||||
|
||||
#mocha .test.pass.slow .duration {
|
||||
background: #B94A48;
|
||||
}
|
||||
|
||||
#mocha .test.pass::before {
|
||||
content: '✓';
|
||||
font-size: 12px;
|
||||
display: block;
|
||||
float: left;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
#mocha .test.pass .duration {
|
||||
font-size: 9px;
|
||||
margin-left: 5px;
|
||||
padding: 2px 5px;
|
||||
color: white;
|
||||
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
|
||||
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
-ms-border-radius: 5px;
|
||||
-o-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#mocha .test.pass.fast .duration {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#mocha .test.pending {
|
||||
color: #0b97c4;
|
||||
}
|
||||
|
||||
#mocha .test.pending::before {
|
||||
content: '◦';
|
||||
color: #0b97c4;
|
||||
}
|
||||
|
||||
#mocha .test.fail {
|
||||
color: #c00;
|
||||
}
|
||||
|
||||
#mocha .test.fail pre {
|
||||
color: black;
|
||||
}
|
||||
|
||||
#mocha .test.fail::before {
|
||||
content: '✖';
|
||||
font-size: 12px;
|
||||
display: block;
|
||||
float: left;
|
||||
margin-right: 5px;
|
||||
color: #c00;
|
||||
}
|
||||
|
||||
#mocha .test pre.error {
|
||||
color: #c00;
|
||||
}
|
||||
|
||||
#mocha .test pre {
|
||||
display: inline-block;
|
||||
font: 12px/1.5 monaco, monospace;
|
||||
margin: 5px;
|
||||
padding: 15px;
|
||||
border: 1px solid #eee;
|
||||
border-bottom-color: #ddd;
|
||||
-webkit-border-radius: 3px;
|
||||
-webkit-box-shadow: 0 1px 3px #eee;
|
||||
}
|
||||
|
||||
#error {
|
||||
color: #c00;
|
||||
font-size: 1.5 em;
|
||||
font-weight: 100;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
#stats {
|
||||
position: fixed;
|
||||
top: 15px;
|
||||
right: 10px;
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
#stats .progress {
|
||||
float: right;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
#stats em {
|
||||
color: black;
|
||||
}
|
||||
|
||||
#stats li {
|
||||
display: inline-block;
|
||||
margin: 0 5px;
|
||||
list-style: none;
|
||||
padding-top: 11px;
|
||||
}
|
||||
|
||||
code .comment { color: #ddd }
|
||||
code .init { color: #2F6FAD }
|
||||
code .string { color: #5890AD }
|
||||
code .keyword { color: #8A6343 }
|
||||
code .number { color: #2F6FAD }
|
||||
4201
test/node_modules/qs/test/browser/mocha.js
generated
vendored
Normal file
4201
test/node_modules/qs/test/browser/mocha.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
0
test/node_modules/qs/test/browser/qs.css
generated
vendored
Normal file
0
test/node_modules/qs/test/browser/qs.css
generated
vendored
Normal file
351
test/node_modules/qs/test/browser/qs.js
generated
vendored
Normal file
351
test/node_modules/qs/test/browser/qs.js
generated
vendored
Normal file
@@ -0,0 +1,351 @@
|
||||
|
||||
/**
|
||||
* Require the given path.
|
||||
*
|
||||
* @param {String} path
|
||||
* @return {Object} exports
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function require(p, parent){
|
||||
var path = require.resolve(p)
|
||||
, mod = require.modules[path];
|
||||
if (!mod) throw new Error('failed to require "' + p + '" in ' + parent);
|
||||
if (!mod.exports) {
|
||||
mod.exports = {};
|
||||
mod.client = true;
|
||||
mod.call(mod.exports, mod, mod.exports, require.relative(path));
|
||||
}
|
||||
return mod.exports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registered modules.
|
||||
*/
|
||||
|
||||
require.modules = {};
|
||||
|
||||
/**
|
||||
* Resolve `path`.
|
||||
*
|
||||
* @param {String} path
|
||||
* @return {Object} module
|
||||
* @api public
|
||||
*/
|
||||
|
||||
require.resolve = function(path){
|
||||
var orig = path
|
||||
, reg = path + '.js'
|
||||
, index = path + '/index.js';
|
||||
return require.modules[reg] && reg
|
||||
|| require.modules[index] && index
|
||||
|| orig;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register module at `path` with callback `fn`.
|
||||
*
|
||||
* @param {String} path
|
||||
* @param {Function} fn
|
||||
* @api public
|
||||
*/
|
||||
|
||||
require.register = function(path, fn){
|
||||
require.modules[path] = fn;
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines and executes anonymous module immediately, while preserving relative
|
||||
* paths.
|
||||
*
|
||||
* @param {String} path
|
||||
* @param {Function} require ref
|
||||
* @api public
|
||||
*/
|
||||
|
||||
require.exec = function (path, fn) {
|
||||
fn.call(window, require.relative(path));
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a require function relative to the `parent` path.
|
||||
*
|
||||
* @param {String} parent
|
||||
* @return {Function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
require.relative = function(parent) {
|
||||
return function(p){
|
||||
if ('.' != p[0]) return require(p);
|
||||
|
||||
var path = parent.split('/')
|
||||
, segs = p.split('/');
|
||||
path.pop();
|
||||
|
||||
for (var i = 0; i < segs.length; i++) {
|
||||
var seg = segs[i];
|
||||
if ('..' == seg) path.pop();
|
||||
else if ('.' != seg) path.push(seg);
|
||||
}
|
||||
|
||||
return require(path.join('/'), parent);
|
||||
};
|
||||
};
|
||||
// component qs: querystring
|
||||
require.register("querystring", function(module, exports, require){
|
||||
;(function(){
|
||||
|
||||
/**
|
||||
* Object#toString() ref for stringify().
|
||||
*/
|
||||
|
||||
var toString = Object.prototype.toString;
|
||||
|
||||
/**
|
||||
* Cache non-integer test regexp.
|
||||
*/
|
||||
|
||||
var isint = /^[0-9]+$/;
|
||||
|
||||
function promote(parent, key) {
|
||||
if (parent[key].length == 0) return parent[key] = {};
|
||||
var t = {};
|
||||
for (var i in parent[key]) t[i] = parent[key][i];
|
||||
parent[key] = t;
|
||||
return t;
|
||||
}
|
||||
|
||||
function parse(parts, parent, key, val) {
|
||||
var part = parts.shift();
|
||||
// end
|
||||
if (!part) {
|
||||
if (Array.isArray(parent[key])) {
|
||||
parent[key].push(val);
|
||||
} else if ('object' == typeof parent[key]) {
|
||||
parent[key] = val;
|
||||
} else if ('undefined' == typeof parent[key]) {
|
||||
parent[key] = val;
|
||||
} else {
|
||||
parent[key] = [parent[key], val];
|
||||
}
|
||||
// array
|
||||
} else {
|
||||
var obj = parent[key] = parent[key] || [];
|
||||
if (']' == part) {
|
||||
if (Array.isArray(obj)) {
|
||||
if ('' != val) obj.push(val);
|
||||
} else if ('object' == typeof obj) {
|
||||
obj[Object.keys(obj).length] = val;
|
||||
} else {
|
||||
obj = parent[key] = [parent[key], val];
|
||||
}
|
||||
// prop
|
||||
} else if (~part.indexOf(']')) {
|
||||
part = part.substr(0, part.length - 1);
|
||||
if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
|
||||
parse(parts, obj, part, val);
|
||||
// key
|
||||
} else {
|
||||
if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
|
||||
parse(parts, obj, part, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge parent key/val pair.
|
||||
*/
|
||||
|
||||
function merge(parent, key, val){
|
||||
if (~key.indexOf(']')) {
|
||||
var parts = key.split('[')
|
||||
, len = parts.length
|
||||
, last = len - 1;
|
||||
parse(parts, parent, 'base', val);
|
||||
// optimize
|
||||
} else {
|
||||
if (!isint.test(key) && Array.isArray(parent.base)) {
|
||||
var t = {};
|
||||
for (var k in parent.base) t[k] = parent.base[k];
|
||||
parent.base = t;
|
||||
}
|
||||
set(parent.base, key, val);
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given obj.
|
||||
*/
|
||||
|
||||
function parseObject(obj){
|
||||
var ret = { base: {} };
|
||||
Object.keys(obj).forEach(function(name){
|
||||
merge(ret, name, obj[name]);
|
||||
});
|
||||
return ret.base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given str.
|
||||
*/
|
||||
|
||||
function parseString(str){
|
||||
return String(str)
|
||||
.split('&')
|
||||
.reduce(function(ret, pair){
|
||||
try{
|
||||
pair = decodeURIComponent(pair.replace(/\+/g, ' '));
|
||||
} catch(e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
var eql = pair.indexOf('=')
|
||||
, brace = lastBraceInKey(pair)
|
||||
, key = pair.substr(0, brace || eql)
|
||||
, val = pair.substr(brace || eql, pair.length)
|
||||
, val = val.substr(val.indexOf('=') + 1, val.length);
|
||||
|
||||
// ?foo
|
||||
if ('' == key) key = pair, val = '';
|
||||
|
||||
return merge(ret, key, val);
|
||||
}, { base: {} }).base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given query `str` or `obj`, returning an object.
|
||||
*
|
||||
* @param {String} str | {Object} obj
|
||||
* @return {Object}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.parse = function(str){
|
||||
if (null == str || '' == str) return {};
|
||||
return 'object' == typeof str
|
||||
? parseObject(str)
|
||||
: parseString(str);
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn the given `obj` into a query string
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
var stringify = exports.stringify = function(obj, prefix) {
|
||||
if (Array.isArray(obj)) {
|
||||
return stringifyArray(obj, prefix);
|
||||
} else if ('[object Object]' == toString.call(obj)) {
|
||||
return stringifyObject(obj, prefix);
|
||||
} else if ('string' == typeof obj) {
|
||||
return stringifyString(obj, prefix);
|
||||
} else {
|
||||
return prefix + '=' + obj;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stringify the given `str`.
|
||||
*
|
||||
* @param {String} str
|
||||
* @param {String} prefix
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function stringifyString(str, prefix) {
|
||||
if (!prefix) throw new TypeError('stringify expects an object');
|
||||
return prefix + '=' + encodeURIComponent(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify the given `arr`.
|
||||
*
|
||||
* @param {Array} arr
|
||||
* @param {String} prefix
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function stringifyArray(arr, prefix) {
|
||||
var ret = [];
|
||||
if (!prefix) throw new TypeError('stringify expects an object');
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
ret.push(stringify(arr[i], prefix + '['+i+']'));
|
||||
}
|
||||
return ret.join('&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify the given `obj`.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @param {String} prefix
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function stringifyObject(obj, prefix) {
|
||||
var ret = []
|
||||
, keys = Object.keys(obj)
|
||||
, key;
|
||||
|
||||
for (var i = 0, len = keys.length; i < len; ++i) {
|
||||
key = keys[i];
|
||||
ret.push(stringify(obj[key], prefix
|
||||
? prefix + '[' + encodeURIComponent(key) + ']'
|
||||
: encodeURIComponent(key)));
|
||||
}
|
||||
|
||||
return ret.join('&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set `obj`'s `key` to `val` respecting
|
||||
* the weird and wonderful syntax of a qs,
|
||||
* where "foo=bar&foo=baz" becomes an array.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @param {String} key
|
||||
* @param {String} val
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function set(obj, key, val) {
|
||||
var v = obj[key];
|
||||
if (undefined === v) {
|
||||
obj[key] = val;
|
||||
} else if (Array.isArray(v)) {
|
||||
v.push(val);
|
||||
} else {
|
||||
obj[key] = [v, val];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate last brace in `str` within the key.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function lastBraceInKey(str) {
|
||||
var len = str.length
|
||||
, brace
|
||||
, c;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
c = str[i];
|
||||
if (']' == c) brace = false;
|
||||
if ('[' == c) brace = true;
|
||||
if ('=' == c && !brace) return i;
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
147
test/node_modules/qs/test/parse.js
generated
vendored
Normal file
147
test/node_modules/qs/test/parse.js
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
|
||||
if (require.register) {
|
||||
var qs = require('querystring');
|
||||
} else {
|
||||
var qs = require('../')
|
||||
, expect = require('expect.js');
|
||||
}
|
||||
|
||||
describe('qs.parse()', function(){
|
||||
it('should support the basics', function(){
|
||||
expect(qs.parse('0=foo')).to.eql({ '0': 'foo' });
|
||||
|
||||
expect(qs.parse('foo=c++'))
|
||||
.to.eql({ foo: 'c ' });
|
||||
|
||||
expect(qs.parse('a[>=]=23'))
|
||||
.to.eql({ a: { '>=': '23' }});
|
||||
|
||||
expect(qs.parse('a[<=>]==23'))
|
||||
.to.eql({ a: { '<=>': '=23' }});
|
||||
|
||||
expect(qs.parse('a[==]=23'))
|
||||
.to.eql({ a: { '==': '23' }});
|
||||
|
||||
expect(qs.parse('foo'))
|
||||
.to.eql({ foo: '' });
|
||||
|
||||
expect(qs.parse('foo=bar'))
|
||||
.to.eql({ foo: 'bar' });
|
||||
|
||||
expect(qs.parse(' foo = bar = baz '))
|
||||
.to.eql({ ' foo ': ' bar = baz ' });
|
||||
|
||||
expect(qs.parse('foo=bar=baz'))
|
||||
.to.eql({ foo: 'bar=baz' });
|
||||
|
||||
expect(qs.parse('foo=bar&bar=baz'))
|
||||
.to.eql({ foo: 'bar', bar: 'baz' });
|
||||
|
||||
expect(qs.parse('foo=bar&baz'))
|
||||
.to.eql({ foo: 'bar', baz: '' });
|
||||
|
||||
expect(qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World'))
|
||||
.to.eql({
|
||||
cht: 'p3'
|
||||
, chd: 't:60,40'
|
||||
, chs: '250x100'
|
||||
, chl: 'Hello|World'
|
||||
});
|
||||
})
|
||||
|
||||
it('should support encoded = signs', function(){
|
||||
expect(qs.parse('he%3Dllo=th%3Dere'))
|
||||
.to.eql({ 'he=llo': 'th=ere' });
|
||||
})
|
||||
|
||||
it('should support nesting', function(){
|
||||
expect(qs.parse('ops[>=]=25'))
|
||||
.to.eql({ ops: { '>=': '25' }});
|
||||
|
||||
expect(qs.parse('user[name]=tj'))
|
||||
.to.eql({ user: { name: 'tj' }});
|
||||
|
||||
expect(qs.parse('user[name][first]=tj&user[name][last]=holowaychuk'))
|
||||
.to.eql({ user: { name: { first: 'tj', last: 'holowaychuk' }}});
|
||||
})
|
||||
|
||||
it('should support array notation', function(){
|
||||
expect(qs.parse('images[]'))
|
||||
.to.eql({ images: [] });
|
||||
|
||||
expect(qs.parse('user[]=tj'))
|
||||
.to.eql({ user: ['tj'] });
|
||||
|
||||
expect(qs.parse('user[]=tj&user[]=tobi&user[]=jane'))
|
||||
.to.eql({ user: ['tj', 'tobi', 'jane'] });
|
||||
|
||||
expect(qs.parse('user[names][]=tj&user[names][]=tyler'))
|
||||
.to.eql({ user: { names: ['tj', 'tyler'] }});
|
||||
|
||||
expect(qs.parse('user[names][]=tj&user[names][]=tyler&user[email]=tj@vision-media.ca'))
|
||||
.to.eql({ user: { names: ['tj', 'tyler'], email: 'tj@vision-media.ca' }});
|
||||
|
||||
expect(qs.parse('items=a&items=b'))
|
||||
.to.eql({ items: ['a', 'b'] });
|
||||
|
||||
expect(qs.parse('user[names]=tj&user[names]=holowaychuk&user[names]=TJ'))
|
||||
.to.eql({ user: { names: ['tj', 'holowaychuk', 'TJ'] }});
|
||||
|
||||
expect(qs.parse('user[name][first]=tj&user[name][first]=TJ'))
|
||||
.to.eql({ user: { name: { first: ['tj', 'TJ'] }}});
|
||||
|
||||
var o = qs.parse('existing[fcbaebfecc][name][last]=tj')
|
||||
expect(o).to.eql({ existing: { 'fcbaebfecc': { name: { last: 'tj' }}}})
|
||||
expect(Array.isArray(o.existing)).to.equal(false);
|
||||
})
|
||||
|
||||
it('should support arrays with indexes', function(){
|
||||
expect(qs.parse('foo[0]=bar&foo[1]=baz')).to.eql({ foo: ['bar', 'baz'] });
|
||||
expect(qs.parse('foo[1]=bar&foo[0]=baz')).to.eql({ foo: ['baz', 'bar'] });
|
||||
expect(qs.parse('foo[base64]=RAWR')).to.eql({ foo: { base64: 'RAWR' }});
|
||||
expect(qs.parse('foo[64base]=RAWR')).to.eql({ foo: { '64base': 'RAWR' }});
|
||||
})
|
||||
|
||||
it('should expand to an array when dupliate keys are present', function(){
|
||||
expect(qs.parse('items=bar&items=baz&items=raz'))
|
||||
.to.eql({ items: ['bar', 'baz', 'raz'] });
|
||||
})
|
||||
|
||||
it('should support right-hand side brackets', function(){
|
||||
expect(qs.parse('pets=["tobi"]'))
|
||||
.to.eql({ pets: '["tobi"]' });
|
||||
|
||||
expect(qs.parse('operators=[">=", "<="]'))
|
||||
.to.eql({ operators: '[">=", "<="]' });
|
||||
|
||||
expect(qs.parse('op[>=]=[1,2,3]'))
|
||||
.to.eql({ op: { '>=': '[1,2,3]' }});
|
||||
|
||||
expect(qs.parse('op[>=]=[1,2,3]&op[=]=[[[[1]]]]'))
|
||||
.to.eql({ op: { '>=': '[1,2,3]', '=': '[[[[1]]]]' }});
|
||||
})
|
||||
|
||||
it('should support empty values', function(){
|
||||
expect(qs.parse('')).to.eql({});
|
||||
expect(qs.parse(undefined)).to.eql({});
|
||||
expect(qs.parse(null)).to.eql({});
|
||||
})
|
||||
|
||||
it('should transform arrays to objects', function(){
|
||||
expect(qs.parse('foo[0]=bar&foo[bad]=baz')).to.eql({ foo: { 0: "bar", bad: "baz" }});
|
||||
expect(qs.parse('foo[bad]=baz&foo[0]=bar')).to.eql({ foo: { 0: "bar", bad: "baz" }});
|
||||
})
|
||||
|
||||
it('should support malformed uri chars', function(){
|
||||
expect(qs.parse('{%:%}')).to.eql({ '{%:%}': '' });
|
||||
expect(qs.parse('foo=%:%}')).to.eql({ 'foo': '%:%}' });
|
||||
})
|
||||
|
||||
it('should support semi-parsed strings', function(){
|
||||
expect(qs.parse({ 'user[name]': 'tobi' }))
|
||||
.to.eql({ user: { name: 'tobi' }});
|
||||
|
||||
expect(qs.parse({ 'user[name]': 'tobi', 'user[email][main]': 'tobi@lb.com' }))
|
||||
.to.eql({ user: { name: 'tobi', email: { main: 'tobi@lb.com' } }});
|
||||
})
|
||||
})
|
||||
79
test/node_modules/qs/test/stringify.js
generated
vendored
Normal file
79
test/node_modules/qs/test/stringify.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
if (require.register) {
|
||||
var qs = require('querystring');
|
||||
} else {
|
||||
var qs = require('../')
|
||||
, expect = require('expect.js');
|
||||
}
|
||||
|
||||
var date = new Date(0);
|
||||
|
||||
var str_identities = {
|
||||
'basics': [
|
||||
{ str: 'foo=bar', obj: {'foo' : 'bar'}},
|
||||
{ str: 'foo=%22bar%22', obj: {'foo' : '\"bar\"'}},
|
||||
{ str: 'foo=', obj: {'foo': ''}},
|
||||
{ str: 'foo=1&bar=2', obj: {'foo' : '1', 'bar' : '2'}},
|
||||
{ str: 'my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F', obj: {'my weird field': "q1!2\"'w$5&7/z8)?"}},
|
||||
{ str: 'foo%3Dbaz=bar', obj: {'foo=baz': 'bar'}},
|
||||
{ str: 'foo=bar&bar=baz', obj: {foo: 'bar', bar: 'baz'}}
|
||||
],
|
||||
'escaping': [
|
||||
{ str: 'foo=foo%20bar', obj: {foo: 'foo bar'}},
|
||||
{ str: 'cht=p3&chd=t%3A60%2C40&chs=250x100&chl=Hello%7CWorld', obj: {
|
||||
cht: 'p3'
|
||||
, chd: 't:60,40'
|
||||
, chs: '250x100'
|
||||
, chl: 'Hello|World'
|
||||
}}
|
||||
],
|
||||
'nested': [
|
||||
{ str: 'foo[0]=bar&foo[1]=quux', obj: {'foo' : ['bar', 'quux']}},
|
||||
{ str: 'foo[0]=bar', obj: {foo: ['bar']}},
|
||||
{ str: 'foo[0]=1&foo[1]=2', obj: {'foo' : ['1', '2']}},
|
||||
{ str: 'foo=bar&baz[0]=1&baz[1]=2&baz[2]=3', obj: {'foo' : 'bar', 'baz' : ['1', '2', '3']}},
|
||||
{ str: 'foo[0]=bar&baz[0]=1&baz[1]=2&baz[2]=3', obj: {'foo' : ['bar'], 'baz' : ['1', '2', '3']}},
|
||||
{ str: 'x[y][z]=1', obj: {'x' : {'y' : {'z' : '1'}}}},
|
||||
{ str: 'x[y][z][0]=1', obj: {'x' : {'y' : {'z' : ['1']}}}},
|
||||
{ str: 'x[y][z]=2', obj: {'x' : {'y' : {'z' : '2'}}}},
|
||||
{ str: 'x[y][z][0]=1&x[y][z][1]=2', obj: {'x' : {'y' : {'z' : ['1', '2']}}}},
|
||||
{ str: 'x[y][0][z]=1', obj: {'x' : {'y' : [{'z' : '1'}]}}},
|
||||
{ str: 'x[y][0][z][0]=1', obj: {'x' : {'y' : [{'z' : ['1']}]}}},
|
||||
{ str: 'x[y][0][z]=1&x[y][0][w]=2', obj: {'x' : {'y' : [{'z' : '1', 'w' : '2'}]}}},
|
||||
{ str: 'x[y][0][v][w]=1', obj: {'x' : {'y' : [{'v' : {'w' : '1'}}]}}},
|
||||
{ str: 'x[y][0][z]=1&x[y][0][v][w]=2', obj: {'x' : {'y' : [{'z' : '1', 'v' : {'w' : '2'}}]}}},
|
||||
{ str: 'x[y][0][z]=1&x[y][1][z]=2', obj: {'x' : {'y' : [{'z' : '1'}, {'z' : '2'}]}}},
|
||||
{ str: 'x[y][0][z]=1&x[y][0][w]=a&x[y][1][z]=2&x[y][1][w]=3', obj: {'x' : {'y' : [{'z' : '1', 'w' : 'a'}, {'z' : '2', 'w' : '3'}]}}},
|
||||
{ str: 'user[name][first]=tj&user[name][last]=holowaychuk', obj: { user: { name: { first: 'tj', last: 'holowaychuk' }}}}
|
||||
],
|
||||
'errors': [
|
||||
{ obj: 'foo=bar', message: 'stringify expects an object' },
|
||||
{ obj: ['foo', 'bar'], message: 'stringify expects an object' }
|
||||
],
|
||||
'numbers': [
|
||||
{ str: 'limit[0]=1&limit[1]=2&limit[2]=3', obj: { limit: [1, 2, '3'] }},
|
||||
{ str: 'limit=1', obj: { limit: 1 }}
|
||||
],
|
||||
'others': [
|
||||
{ str: 'at=' + encodeURIComponent(date), obj: { at: date } }
|
||||
]
|
||||
};
|
||||
|
||||
function test(type) {
|
||||
return function(){
|
||||
var str, obj;
|
||||
for (var i = 0; i < str_identities[type].length; i++) {
|
||||
str = str_identities[type][i].str;
|
||||
obj = str_identities[type][i].obj;
|
||||
expect(qs.stringify(obj)).to.eql(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('qs.stringify()', function(){
|
||||
it('should support the basics', test('basics'))
|
||||
it('should support escapes', test('escaping'))
|
||||
it('should support nesting', test('nested'))
|
||||
it('should support numbers', test('numbers'))
|
||||
it('should support others', test('others'))
|
||||
})
|
||||
BIN
test/node_modules/querystring/.History.md.un~
generated
vendored
Normal file
BIN
test/node_modules/querystring/.History.md.un~
generated
vendored
Normal file
Binary file not shown.
BIN
test/node_modules/querystring/.package.json.un~
generated
vendored
Normal file
BIN
test/node_modules/querystring/.package.json.un~
generated
vendored
Normal file
Binary file not shown.
7
test/node_modules/querystring/History.md
generated
vendored
Normal file
7
test/node_modules/querystring/History.md
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# 0.0.3 / 2011-04-16 #
|
||||
- Support for AMD module loaders
|
||||
# 0.0.2 / 2011-04-16 #
|
||||
- Ported unit tests
|
||||
- Removed functionality that depended on Buffers
|
||||
# 0.0.1 / 2011-04-15 #
|
||||
- Initial release
|
||||
8
test/node_modules/querystring/Readme.md
generated
vendored
Normal file
8
test/node_modules/querystring/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# querystring #
|
||||
|
||||
Node's querystring module for all engines.
|
||||
|
||||
## Install ##
|
||||
|
||||
npm install querystring
|
||||
|
||||
40
test/node_modules/querystring/package.json
generated
vendored
Normal file
40
test/node_modules/querystring/package.json
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "querystring",
|
||||
"id": "querystring",
|
||||
"version": "0.1.0",
|
||||
"description": "Node's querystring module for all engines.",
|
||||
"keywords": [
|
||||
"commonjs",
|
||||
"query",
|
||||
"querystring"
|
||||
],
|
||||
"author": {
|
||||
"name": "Irakli Gozalishvili",
|
||||
"email": "rfobic@gmail.com"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/Gozala/querystring.git",
|
||||
"web": "https://github.com/Gozala/querystring"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/Gozala/querystring/issues/"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": ">=0.4.3"
|
||||
},
|
||||
"main": "./querystring.js",
|
||||
"engines": {
|
||||
"node": ">=0.4.x"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node tests/test-querystring.js"
|
||||
},
|
||||
"readme": "# querystring #\n\nNode's querystring module for all engines.\n\n## Install ##\n\n npm install querystring\n\n",
|
||||
"readmeFilename": "Readme.md",
|
||||
"_id": "querystring@0.1.0",
|
||||
"dist": {
|
||||
"shasum": "210af37f82b5fa9a52a05982a2b27607e97c01bb"
|
||||
},
|
||||
"_from": "querystring"
|
||||
}
|
||||
108
test/node_modules/querystring/querystring.js
generated
vendored
Normal file
108
test/node_modules/querystring/querystring.js
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// Query String Utilities
|
||||
|
||||
(typeof define === "undefined" ? function($) { $(require, exports, module) } : define)(function(require, exports, module, undefined) {
|
||||
"use strict";
|
||||
|
||||
var QueryString = exports;
|
||||
|
||||
function charCode(c) {
|
||||
return c.charCodeAt(0);
|
||||
}
|
||||
|
||||
QueryString.unescape = decodeURIComponent;
|
||||
QueryString.escape = encodeURIComponent;
|
||||
|
||||
var stringifyPrimitive = function(v) {
|
||||
switch (typeof v) {
|
||||
case 'string':
|
||||
return v;
|
||||
|
||||
case 'boolean':
|
||||
return v ? 'true' : 'false';
|
||||
|
||||
case 'number':
|
||||
return isFinite(v) ? v : '';
|
||||
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QueryString.stringify = QueryString.encode = function(obj, sep, eq, name) {
|
||||
sep = sep || '&';
|
||||
eq = eq || '=';
|
||||
obj = (obj === null) ? undefined : obj;
|
||||
|
||||
switch (typeof obj) {
|
||||
case 'object':
|
||||
return Object.keys(obj).map(function(k) {
|
||||
if (Array.isArray(obj[k])) {
|
||||
return obj[k].map(function(v) {
|
||||
return QueryString.escape(stringifyPrimitive(k)) +
|
||||
eq +
|
||||
QueryString.escape(stringifyPrimitive(v));
|
||||
}).join(sep);
|
||||
} else {
|
||||
return QueryString.escape(stringifyPrimitive(k)) +
|
||||
eq +
|
||||
QueryString.escape(stringifyPrimitive(obj[k]));
|
||||
}
|
||||
}).join(sep);
|
||||
|
||||
default:
|
||||
if (!name) return '';
|
||||
return QueryString.escape(stringifyPrimitive(name)) + eq +
|
||||
QueryString.escape(stringifyPrimitive(obj));
|
||||
}
|
||||
};
|
||||
|
||||
// Parse a key=val string.
|
||||
QueryString.parse = QueryString.decode = function(qs, sep, eq) {
|
||||
sep = sep || '&';
|
||||
eq = eq || '=';
|
||||
var obj = {};
|
||||
|
||||
if (typeof qs !== 'string' || qs.length === 0) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
qs.split(sep).forEach(function(kvp) {
|
||||
var x = kvp.split(eq);
|
||||
var k = QueryString.unescape(x[0], true);
|
||||
var v = QueryString.unescape(x.slice(1).join(eq), true);
|
||||
|
||||
if (!(k in obj)) {
|
||||
obj[k] = v;
|
||||
} else if (!Array.isArray(obj[k])) {
|
||||
obj[k] = [obj[k], v];
|
||||
} else {
|
||||
obj[k].push(v);
|
||||
}
|
||||
});
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
});
|
||||
BIN
test/node_modules/querystring/tests/.test-querystring.js.un~
generated
vendored
Normal file
BIN
test/node_modules/querystring/tests/.test-querystring.js.un~
generated
vendored
Normal file
Binary file not shown.
203
test/node_modules/querystring/tests/test-querystring.js
generated
vendored
Normal file
203
test/node_modules/querystring/tests/test-querystring.js
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
"use strict";
|
||||
|
||||
// test using assert
|
||||
var qs = require('../querystring');
|
||||
|
||||
// folding block, commented to pass gjslint
|
||||
// {{{
|
||||
// [ wonkyQS, canonicalQS, obj ]
|
||||
var qsTestCases = [
|
||||
['foo=918854443121279438895193',
|
||||
'foo=918854443121279438895193',
|
||||
{'foo': '918854443121279438895193'}],
|
||||
['foo=bar', 'foo=bar', {'foo': 'bar'}],
|
||||
['foo=bar&foo=quux', 'foo=bar&foo=quux', {'foo': ['bar', 'quux']}],
|
||||
['foo=1&bar=2', 'foo=1&bar=2', {'foo': '1', 'bar': '2'}],
|
||||
// ['my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F',
|
||||
// 'my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F',
|
||||
// {'my weird field': 'q1!2"\'w$5&7/z8)?' }],
|
||||
['foo%3Dbaz=bar', 'foo%3Dbaz=bar', {'foo=baz': 'bar'}],
|
||||
['foo=baz=bar', 'foo=baz%3Dbar', {'foo': 'baz=bar'}],
|
||||
['str=foo&arr=1&arr=2&arr=3&somenull=&undef=',
|
||||
'str=foo&arr=1&arr=2&arr=3&somenull=&undef=',
|
||||
{ 'str': 'foo',
|
||||
'arr': ['1', '2', '3'],
|
||||
'somenull': '',
|
||||
'undef': ''}],
|
||||
[' foo = bar ', '%20foo%20=%20bar%20', {' foo ': ' bar '}],
|
||||
// disable test that fails ['foo=%zx', 'foo=%25zx', {'foo': '%zx'}],
|
||||
['foo=%EF%BF%BD', 'foo=%EF%BF%BD', {'foo': '\ufffd' }]
|
||||
];
|
||||
|
||||
// [ wonkyQS, canonicalQS, obj ]
|
||||
var qsColonTestCases = [
|
||||
['foo:bar', 'foo:bar', {'foo': 'bar'}],
|
||||
['foo:bar;foo:quux', 'foo:bar;foo:quux', {'foo': ['bar', 'quux']}],
|
||||
['foo:1&bar:2;baz:quux',
|
||||
'foo:1%26bar%3A2;baz:quux',
|
||||
{'foo': '1&bar:2', 'baz': 'quux'}],
|
||||
['foo%3Abaz:bar', 'foo%3Abaz:bar', {'foo:baz': 'bar'}],
|
||||
['foo:baz:bar', 'foo:baz%3Abar', {'foo': 'baz:bar'}]
|
||||
];
|
||||
|
||||
// [wonkyObj, qs, canonicalObj]
|
||||
var extendedFunction = function() {};
|
||||
extendedFunction.prototype = {a: 'b'};
|
||||
var qsWeirdObjects = [
|
||||
[{regexp: /./g}, 'regexp=', {'regexp': ''}],
|
||||
[{regexp: new RegExp('.', 'g')}, 'regexp=', {'regexp': ''}],
|
||||
[{fn: function() {}}, 'fn=', {'fn': ''}],
|
||||
[{fn: new Function('')}, 'fn=', {'fn': ''}],
|
||||
[{math: Math}, 'math=', {'math': ''}],
|
||||
[{e: extendedFunction}, 'e=', {'e': ''}],
|
||||
[{d: new Date()}, 'd=', {'d': ''}],
|
||||
[{d: Date}, 'd=', {'d': ''}],
|
||||
[{f: new Boolean(false), t: new Boolean(true)}, 'f=&t=', {'f': '', 't': ''}],
|
||||
[{f: false, t: true}, 'f=false&t=true', {'f': 'false', 't': 'true'}],
|
||||
[{n: null}, 'n=', {'n': ''}],
|
||||
[{nan: NaN}, 'nan=', {'nan': ''}],
|
||||
[{inf: Infinity}, 'inf=', {'inf': ''}]
|
||||
];
|
||||
// }}}
|
||||
|
||||
var qsNoMungeTestCases = [
|
||||
['', {}],
|
||||
['foo=bar&foo=baz', {'foo': ['bar', 'baz']}],
|
||||
['blah=burp', {'blah': 'burp'}],
|
||||
['gragh=1&gragh=3&goo=2', {'gragh': ['1', '3'], 'goo': '2'}],
|
||||
['frappucino=muffin&goat%5B%5D=scone&pond=moose',
|
||||
{'frappucino': 'muffin', 'goat[]': 'scone', 'pond': 'moose'}],
|
||||
['trololol=yes&lololo=no', {'trololol': 'yes', 'lololo': 'no'}]
|
||||
];
|
||||
|
||||
exports['test basic'] = function(assert) {
|
||||
assert.strictEqual('918854443121279438895193',
|
||||
qs.parse('id=918854443121279438895193').id,
|
||||
'prase id=918854443121279438895193');
|
||||
};
|
||||
|
||||
exports['test that the canonical qs is parsed properly'] = function(assert) {
|
||||
qsTestCases.forEach(function(testCase) {
|
||||
assert.deepEqual(testCase[2], qs.parse(testCase[0]),
|
||||
'parse ' + testCase[0]);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
exports['test that the colon test cases can do the same'] = function(assert) {
|
||||
qsColonTestCases.forEach(function(testCase) {
|
||||
assert.deepEqual(testCase[2], qs.parse(testCase[0], ';', ':'),
|
||||
'parse ' + testCase[0] + ' -> ; :');
|
||||
});
|
||||
};
|
||||
|
||||
exports['test the weird objects, that they get parsed properly'] = function(assert) {
|
||||
qsWeirdObjects.forEach(function(testCase) {
|
||||
assert.deepEqual(testCase[2], qs.parse(testCase[1]),
|
||||
'parse ' + testCase[1]);
|
||||
});
|
||||
};
|
||||
|
||||
exports['test non munge test cases'] = function(assert) {
|
||||
qsNoMungeTestCases.forEach(function(testCase) {
|
||||
assert.deepEqual(testCase[0], qs.stringify(testCase[1], '&', '=', false),
|
||||
'stringify ' + JSON.stringify(testCase[1]) + ' -> & =');
|
||||
});
|
||||
};
|
||||
|
||||
exports['test the nested qs-in-qs case'] = function(assert) {
|
||||
var f = qs.parse('a=b&q=x%3Dy%26y%3Dz');
|
||||
f.q = qs.parse(f.q);
|
||||
assert.deepEqual(f, { a: 'b', q: { x: 'y', y: 'z' } },
|
||||
'parse a=b&q=x%3Dy%26y%3Dz');
|
||||
};
|
||||
|
||||
exports['test nested in colon'] = function(assert) {
|
||||
var f = qs.parse('a:b;q:x%3Ay%3By%3Az', ';', ':');
|
||||
f.q = qs.parse(f.q, ';', ':');
|
||||
assert.deepEqual(f, { a: 'b', q: { x: 'y', y: 'z' } },
|
||||
'parse a:b;q:x%3Ay%3By%3Az -> ; :');
|
||||
};
|
||||
|
||||
exports['test stringifying'] = function(assert) {
|
||||
qsTestCases.forEach(function(testCase) {
|
||||
assert.equal(testCase[1], qs.stringify(testCase[2]),
|
||||
'stringify ' + JSON.stringify(testCase[2]));
|
||||
});
|
||||
|
||||
qsColonTestCases.forEach(function(testCase) {
|
||||
assert.equal(testCase[1], qs.stringify(testCase[2], ';', ':'),
|
||||
'stringify ' + JSON.stringify(testCase[2]) + ' -> ; :');
|
||||
});
|
||||
|
||||
qsWeirdObjects.forEach(function(testCase) {
|
||||
assert.equal(testCase[1], qs.stringify(testCase[0]),
|
||||
'stringify ' + JSON.stringify(testCase[0]));
|
||||
});
|
||||
};
|
||||
|
||||
exports['test stringifying nested'] = function(assert) {
|
||||
var f = qs.stringify({
|
||||
a: 'b',
|
||||
q: qs.stringify({
|
||||
x: 'y',
|
||||
y: 'z'
|
||||
})
|
||||
});
|
||||
assert.equal(f, 'a=b&q=x%3Dy%26y%3Dz',
|
||||
JSON.stringify({
|
||||
a: 'b',
|
||||
'qs.stringify -> q': {
|
||||
x: 'y',
|
||||
y: 'z'
|
||||
}
|
||||
}));
|
||||
|
||||
var threw = false;
|
||||
try { qs.parse(undefined); } catch(error) { threw = true; }
|
||||
assert.ok(!threw, "does not throws on undefined");
|
||||
};
|
||||
|
||||
exports['test nested in colon'] = function(assert) {
|
||||
var f = qs.stringify({
|
||||
a: 'b',
|
||||
q: qs.stringify({
|
||||
x: 'y',
|
||||
y: 'z'
|
||||
}, ';', ':')
|
||||
}, ';', ':');
|
||||
assert.equal(f, 'a:b;q:x%3Ay%3By%3Az',
|
||||
'stringify ' + JSON.stringify({
|
||||
a: 'b',
|
||||
'qs.stringify -> q': {
|
||||
x: 'y',
|
||||
y: 'z'
|
||||
}
|
||||
}) + ' -> ; : ');
|
||||
|
||||
|
||||
assert.deepEqual({}, qs.parse(), 'parse undefined');
|
||||
};
|
||||
|
||||
require("test").run(exports);
|
||||
95
test/routes/articles.js
Normal file
95
test/routes/articles.js
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Article Routes
|
||||
*/
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var Article = require('../data/models/article');
|
||||
var notLoggedIn = require('./middleware/not_logged_in');
|
||||
var loadArticle = require('./middleware/load_article');
|
||||
var loggedIn = require('./middleware/logged_in');
|
||||
|
||||
var maxArticlesPerPage = 5;
|
||||
|
||||
module.exports = function(app) {
|
||||
|
||||
app.get('/articles', function(req, res, next){
|
||||
var page = req.query.page && parseInt(req.query.page, 10) || 0;
|
||||
async.parallel([
|
||||
|
||||
function(next) {
|
||||
Article.count(next);
|
||||
},
|
||||
|
||||
function(next) {
|
||||
Article.find({})
|
||||
//.sort('title', 1)
|
||||
.skip(page * maxArticlesPerPage)
|
||||
.limit(maxArticlesPerPage)
|
||||
.exec(next);
|
||||
}
|
||||
],
|
||||
|
||||
// callback from async
|
||||
function(err, results) {
|
||||
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var count = results[0];
|
||||
var articles = results[1];
|
||||
|
||||
var lastPage = (page + 1) * maxArticlesPerPage >= count;
|
||||
|
||||
res.render('articles/index', {
|
||||
title: 'Articles',
|
||||
articles: articles,
|
||||
page: page,
|
||||
lastPage: lastPage
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
app.get('/articles/new', loggedIn, function(req, res) {
|
||||
res.render('Articles/new', {title: "New Article"});
|
||||
});
|
||||
|
||||
app.get('/articles/:title', loadArticle, function(req, res, next){
|
||||
res.render('articles/article', {title: req.article.title,
|
||||
article: req.article});
|
||||
});
|
||||
|
||||
app.post('/articles', loggedIn, function(req, res, next) {
|
||||
var article = req.body;
|
||||
article.author = req.session.user._id;
|
||||
Article.create(article, function(err) {
|
||||
if (err) {
|
||||
if (err.code === 11000) {
|
||||
res.send('Conflict', 409);
|
||||
} else {
|
||||
if (err.name === 'ValidationError') {
|
||||
return res.send(Object.keys(err.errors).map(function(errField) {
|
||||
return err.errors[errField].message;
|
||||
}).join('. '), 406);
|
||||
} else {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
res.redirect('/articles');
|
||||
});
|
||||
});
|
||||
|
||||
app.del('/articles/:title', loggedIn, loadArticle, function(req, res, next) {
|
||||
req.article.remove(function(err) {
|
||||
if (err) { return next(err); }
|
||||
res.redirect('/articles');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
18
test/routes/middleware/load_article.js
Normal file
18
test/routes/middleware/load_article.js
Normal file
@@ -0,0 +1,18 @@
|
||||
var Article = require('../../data/models/article');
|
||||
|
||||
function loadArticle(req, res, next) {
|
||||
Article.findOne({title: req.params.title})
|
||||
.populate('author')
|
||||
.exec(function(err, article) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (! article) {
|
||||
return res.send('Not found', 404);
|
||||
}
|
||||
req.article = article;
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = loadArticle;
|
||||
9
test/routes/middleware/logged_in.js
Normal file
9
test/routes/middleware/logged_in.js
Normal file
@@ -0,0 +1,9 @@
|
||||
function loggedIn(req, res, next) {
|
||||
if (! req.session.user) {
|
||||
res.send('Forbidden. Please log in first.', 403);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = loggedIn;
|
||||
@@ -12,27 +12,27 @@ module.exports = function(app) {
|
||||
|
||||
app.get('/users', function(req, res, next){
|
||||
var page = req.query.page && parseInt(req.query.page, 10) || 0;
|
||||
|
||||
|
||||
User.count(function(err, count) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
var lastPage = (page + 1) * maxUsersPerPage >= count;
|
||||
|
||||
|
||||
User.find({})
|
||||
.sort('name')
|
||||
.skip(page * maxUsersPerPage)
|
||||
.limit(maxUsersPerPage)
|
||||
.exec(function(err, users) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.render('users/index', {
|
||||
title: 'Users',
|
||||
users: users,
|
||||
page: page,
|
||||
lastPage: lastPage
|
||||
});
|
||||
return next(err);
|
||||
}
|
||||
res.render('users/index', {
|
||||
title: 'Users',
|
||||
users: users,
|
||||
page: page,
|
||||
lastPage: lastPage
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -42,10 +42,21 @@ module.exports = function(app) {
|
||||
});
|
||||
|
||||
app.get('/users/:name', loadUser, function(req, res, next){
|
||||
res.render('users/profile', {title: 'User profile', user: req.user});
|
||||
req.user.recentArticles(function(err, articles) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.render('users/profile', {
|
||||
title: 'User profile',
|
||||
user: req.user,
|
||||
recentArticles: articles
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/users', notLoggedIn, function(req, res, next) {
|
||||
console.log("/nreq.body" + req.body);
|
||||
console.log("/nreq.body" + JSON.stringify(req.body));
|
||||
User.create(req.body, function(err) {
|
||||
if (err) {
|
||||
if (err.code === 11000) {
|
||||
@@ -59,13 +70,13 @@ module.exports = function(app) {
|
||||
});
|
||||
});
|
||||
|
||||
app.del('/users/:name', loadUser, restrictUserToSelf,
|
||||
app.del('/users/:name', loadUser,
|
||||
function(req, res, next) {
|
||||
req.user.remove(function(err) {
|
||||
if (err) { return next(err); }
|
||||
res.redirect('/users');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
13
test/views/articles/article.jade
Normal file
13
test/views/articles/article.jade
Normal file
@@ -0,0 +1,13 @@
|
||||
h1= article.title
|
||||
|
||||
div!= article.body
|
||||
|
||||
hr
|
||||
|
||||
p
|
||||
span Author:
|
||||
|
||||
a(href="/users/" + encodeURIComponent(article.author.username))= article.author.full_name
|
||||
|
||||
p
|
||||
a(href="/articles") Back to all articles
|
||||
15
test/views/articles/index.jade
Normal file
15
test/views/articles/index.jade
Normal file
@@ -0,0 +1,15 @@
|
||||
h1 Articles
|
||||
|
||||
p
|
||||
a(href="/articles/new") Create new article
|
||||
|
||||
p!= partial('articles/list', {articles: articles})
|
||||
|
||||
- if (page > 0) {
|
||||
a(href="?page=" + (page - 1)) Previous
|
||||
|
||||
- }
|
||||
|
||||
- if (! lastPage) {
|
||||
a(href="?page=" + (page + 1)) Next
|
||||
- }
|
||||
5
test/views/articles/list.jade
Normal file
5
test/views/articles/list.jade
Normal file
@@ -0,0 +1,5 @@
|
||||
ul
|
||||
- articles.forEach(function(article) {
|
||||
li
|
||||
a(href="/articles/" + encodeURIComponent(article.title))= article.title
|
||||
- });
|
||||
11
test/views/articles/new.jade
Normal file
11
test/views/articles/new.jade
Normal file
@@ -0,0 +1,11 @@
|
||||
h1 New Article
|
||||
|
||||
form(method="POST", action="/articles")
|
||||
p
|
||||
label(for="title") Title<br />
|
||||
input#title(name="title")
|
||||
p
|
||||
label(for="body") Body<br />
|
||||
textarea#body(name="body")
|
||||
p
|
||||
input(type="submit", value="Create")
|
||||
@@ -1,2 +1,7 @@
|
||||
h1= title
|
||||
p Welcome to #{title}
|
||||
p Welcome to #{title}
|
||||
|
||||
p
|
||||
a(href="/users") List Users
|
||||
p
|
||||
a(href="/articles") List Articles
|
||||
|
||||
@@ -2,6 +2,8 @@ h1 Users
|
||||
|
||||
p
|
||||
a(href="/users/new") Create new profile
|
||||
p
|
||||
a(href="/articles/new") Create new article
|
||||
|
||||
ul
|
||||
- users.forEach(function(user) {
|
||||
|
||||
@@ -10,8 +10,5 @@ form(method="POST", action="/users")
|
||||
p
|
||||
label(for="password") Password<br />
|
||||
input#password(type="password", name="password")
|
||||
p
|
||||
label(for="bio") Bio<br />
|
||||
textarea#bio(name="bio")
|
||||
p
|
||||
input(type="submit", value="Create")
|
||||
@@ -1,7 +1,8 @@
|
||||
h1= user.name
|
||||
|
||||
h2 Bio
|
||||
p= user.bio
|
||||
h2 Recent Articles:
|
||||
p!= partial('articles/list', {articles: recentArticles })
|
||||
|
||||
|
||||
form(action="/users/" + encodeURIComponent(user.username), method="POST")
|
||||
input(name="_method", type="hidden", value="DELETE")
|
||||
|
||||
Reference in New Issue
Block a user