Skip to content
Myr

Merge

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parents 327d5b0, 7e92012 · Browse files · 13 files+258 added−243 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

13 files+258 added−243 removed

  • tests:+78 added−80 removed
  • other:+180 added−163 removed

13 files+258 added−243 removed

modified:examples/chat/app.js+5 added-4 removed
modified:examples/upload/app.js+2 added-2 removed
modified:lib/express/plugins/view.js+3 added-2 removed
3 unmodified lines
4/**5 * Module dependencies.6 */78var posix = require('posix')8var posix = require('posix'),9 utils = require('express/utils')1011/**12 * Supported template engines.13 */
51 unmodified lines
65 var self = this,66 options = options || {},67 path = set('views') + '/' + view,68 type = path.split('.').slice(-2)[0],68 ext = extname(path),69 ext = utils.extname(path),70 layout = options.layout === undefined ? true : options.layout71 self.contentType(ext)72 function render(content) {73 content = engine[type].render(content, options)
26 unmodified lines
modified:lib/express/core.js+28 added-11 removed
4 unmodified lines
5process.mixin(require('express/exceptions'))6process.mixin(require('express/collection'))7process.mixin(require('express/event'))8process.mixin(require('express/request'))9process.mixin(require('express/helpers'))9process.mixin(require('express/plugin'))10process.mixin(require('express/mime'))11process.mixin(require('express/dsl'))1213/**14 * Module dependencies.15 */1617var multipart = require('multipart'),15 File = require('file').File18 File = require('file').File,19 utils = require('express/utils')20 21// --- Route2223Route = Class({
59 unmodified lines
83 normalize: function(path) {84 var self = this85 this.keys = []86 if (path instanceof RegExp) return path83 return new RegExp('^' + escapeRegexp(normalizePath(path), '.')87 return new RegExp('^' + utils.escapeRegexp(normalizePath(path), '.')88 .replace(/\*/g, '(.+)')89 .replace(/(\/|\\\.):(\w+)\?/g, function(_, c, key){90 self.keys.push(key)91 return '(?:' + c + '([^\/]+))?'
130 unmodified lines
222 request.body = ''223 request.setBodyEncoding('binary')224 if (request.headers['content-type'] &&225 request.headers['content-type'].indexOf('multipart/form-data') !== -1) {222 var stream = new multipart.Stream(request)226 var stream = new multipart.Stream(request),227 promise = new process.Promise,228 pendingFiles = 0229 request.params = { post: {}}230 promise.timeout(set('upload timeout') || 5000)231 stream.addListener('part', function(part){232 if (part.filename) {226 var file = new File(part.tempfile = '/tmp/express-' + Number(new Date) + uid(), 'w')233 var file = new File(part.tempfile = '/tmp/express-' + Number(new Date) + utils.uid(), 'w')234 ++pendingFiles235 part.pos = 0236 part.addListener('body', function(chunk){229 file.write(chunk, part.pos, 'binary')237 file.write(chunk, part.pos, 'binary').addErrback(function(){238 promise.emitError.apply(promise, arguments)239 })240 part.pos += chunk.length241 })232 part.addListener('complete', function(){233 file.close()234 mergeParam(part.name, part, request.params.post)242 .addListener('complete', function(){243 file.close().addCallback(function(){244 if (!--pendingFiles)245 promise.emitSuccess()246 }).addErrback(function(){247 promise.emitError.apply(promise, arguments)248 })249 utils.mergeParam(part.name, part, request.params.post)250 })251 }252 else253 part.buf = '',254 part255 .addListener('body', function(chunk){ part.buf += chunk })256 .addListener('complete', function(){257 if (part.buf.length)243 mergeParam(part.name, part.buf, request.params.post)258 utils.mergeParam(part.name, part.buf, request.params.post)259 })245 }).addListener('complete', function(){ self.route(request, response) })260 }).addListener('complete', function(){261 promise.addCallback(function(){ self.route(request, response) })262 })263 }264 else265 request266 .addListener('body', function(chunk){ request.body += chunk })
67 unmodified lines
deleted:lib/express/helpers.js-135 removed
12// Express - Helpers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * JSON aliases.6 */78JSON.encode = JSON.stringify9JSON.decode = JSON.parse1011/**12 * Return a unique identifier.13 *14 * @return {string}15 * @api public16 */1718exports.uid = function() {19 var uid = ''20 for (var n = 4; n; --n)21 uid += (Math.abs((Math.random() * 0xFFFFFFF) | 0)).toString(16)22 return uid23}2425/**26 * Return the directory name of the given _path_.27 *28 * @param {string} path29 * @return {string}30 * @api public31 */3233exports.dirname = function(path) {34 return path.split('/').slice(0, -1).join('/')35}3637/**38 * Return the extension name of the given _path_,39 * or null when not present.40 *41 * @param {string} path42 * @return {string}43 * @api public44 */4546exports.extname = function(path) {47 if (path.lastIndexOf('.') < 0) return48 return path.slice(path.lastIndexOf('.') + 1)49}5051/**52 * Return the basename of the given _path_.53 *54 * @param {string} path55 * @return {string}56 * @api public57 */5859exports.basename = function(path) {60 return path.split('/').slice(-1)[0]61}6263/**64 * Escape special characters in _html_.65 *66 * @param {string} html67 * @return {string}68 * @api public69 */7071exports.escape = function(html) {72 return html.toString()73 .replace(/&/g, '&amp;')74 .replace(/"/g, '&quot;')75 .replace(/</g, '&lt;')76 .replace(/>/g, '&gt;')77}7879/**80 * Convert native array-like objects into an81 * array with optional _offset_.82 *83 * @param {object} arr84 * @param {int} offset85 * @return {array}86 * @api public87 */8889exports.toArray = function(arr, offset) {90 return Array.prototype.slice.call(arr, offset)91}9293/**94 * Escape RegExp _chars_ in _string_. Where _chars_ 95 * defaults to regular expression special characters.96 *97 * _chars_ should be a space delimited list of characters,98 * for example '[ ] ( )'.99 *100 * @param {string} string101 * @param {string} chars102 * @return {Type}103 * @api public104 */105106exports.escapeRegexp = function(string, chars) {107 var specials = (chars || '/ . * + ? | ( ) [ ] { } \\').split(' ').join('|\\')108 return string.replace(new RegExp('(\\' + specials + ')', 'g'), '\\$1')109}110111/**112 * Merge param _key_ and _val_ into _params_. Key113 * should be a query string key such as 'user[name]',114 * and _val_ is it's associated value. The root _params_115 * object is returned.116 *117 * This is primarily used by Express for merging multi-part118 * body values together.119 *120 * @param {string} key121 * @param {string} val122 * @return {hash}123 * @api public124 */125126exports.mergeParam = function(key, val, params) {127 var keys = key.match(/(\w+)/g),128 orig = params129 for (var i = 0, len = keys.length; i < len; ++i)130 if (i == len - 1)131 params[keys[i]] = val132 else133 params = (params[keys[i]] = params[keys[i]] || {})134 return orig135}
modified:lib/express/mime.js+13 added-3 removed
12// Express - Mime - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34var types = {4/**5 * Module dependencies.6 */7 8var utils = require('express/utils')910/**11 * Mime type lookup table.12 */1314exports.types = {15 '323' : 'text/h323',16 '3gp' : 'video/3gpp',17 'a' : 'application/octet-stream',18 'acx' : 'application/internet-property-stream',
342 unmodified lines
361 * @api public362 */363364exports.mime = function(path) {355 return types[path] || 356 types[extname(path)] || 365 return exports.types[path] || 366 exports.types[utils.extname(path)] || 367 set('default mime type') || 368 'application/octet-stream' 369}
added:lib/express/utils.js+123 added
12// Express - Helpers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * JSON aliases.6 */78JSON.encode = JSON.stringify9JSON.decode = JSON.parse1011/**12 * Return a unique identifier.13 *14 * @return {string}15 * @api public16 */1718exports.uid = function() {19 var uid = ''20 for (var n = 4; n; --n)21 uid += (Math.abs((Math.random() * 0xFFFFFFF) | 0)).toString(16)22 return uid23}2425/**26 * Return the extension name of the given _path_,27 * or null when not present.28 *29 * @param {string} path30 * @return {string}31 * @api public32 */3334exports.extname = function(path) {35 if (path.lastIndexOf('.') < 0) return36 return path.slice(path.lastIndexOf('.') + 1)37}3839/**40 * Return the basename of the given _path_.41 *42 * @param {string} path43 * @return {string}44 * @api public45 */4647exports.basename = function(path) {48 return path.split('/').slice(-1)[0]49}5051/**52 * Escape special characters in _html_.53 *54 * @param {string} html55 * @return {string}56 * @api public57 */5859exports.escape = function(html) {60 return html.toString()61 .replace(/&/g, '&amp;')62 .replace(/"/g, '&quot;')63 .replace(/</g, '&lt;')64 .replace(/>/g, '&gt;')65}6667/**68 * Convert native array-like objects into an69 * array with optional _offset_.70 *71 * @param {object} arr72 * @param {int} offset73 * @return {array}74 * @api public75 */7677exports.toArray = function(arr, offset) {78 return Array.prototype.slice.call(arr, offset)79}8081/**82 * Escape RegExp _chars_ in _string_. Where _chars_ 83 * defaults to regular expression special characters.84 *85 * _chars_ should be a space delimited list of characters,86 * for example '[ ] ( )'.87 *88 * @param {string} string89 * @param {string} chars90 * @return {Type}91 * @api public92 */9394exports.escapeRegexp = function(string, chars) {95 var specials = (chars || '/ . * + ? | ( ) [ ] { } \\').split(' ').join('|\\')96 return string.replace(new RegExp('(\\' + specials + ')', 'g'), '\\$1')97}9899/**100 * Merge param _key_ and _val_ into _params_. Key101 * should be a query string key such as 'user[name]',102 * and _val_ is it's associated value. The root _params_103 * object is returned.104 *105 * This is primarily used by Express for merging multi-part106 * body values together.107 *108 * @param {string} key109 * @param {string} val110 * @return {hash}111 * @api public112 */113114exports.mergeParam = function(key, val, params) {115 var keys = key.match(/(\w+)/g),116 orig = params117 for (var i = 0, len = keys.length; i < len; ++i)118 if (i == len - 1)119 params[keys[i]] = val120 else121 params = (params[keys[i]] = params[keys[i]] || {})122 return orig123}
modified:lib/express.js+4 added-4 removed
modified:spec/lib/jspec.js+5 added-5 removed
2 unmodified lines
34;(function(){56 JSpec = {7 version : '3.1.0',7 version : '3.2.1',8 assert : true,9 cache : {},10 suites : [],11 modules : [],
1033 unmodified lines
1045 * @api public1046 */10471048 expect : function(actual) {1049 assert = function(matcher, args, negate) {1049 function assert(matcher, args, negate) {1050 var expected = toArray(args, 1)1051 matcher.negate = negate 1052 assertion = new JSpec.Assertion(matcher, actual, expected, negate)1053 hook('beforeAssertion', assertion)
1 unmodified line
1055 else JSpec.currentSpec.assertions.push(assertion.run().report()), hook('afterAssertion', assertion)1056 return assertion.result1057 }1058 1059 to = function(matcher) {1059 function to(matcher) {1060 return assert(matcher, arguments, false)1061 }1062 1063 not_to = function(matcher) {1063 function not_to(matcher) {1064 return assert(matcher, arguments, true)1065 }1066 1067 return {
623 unmodified lines
1691 case String: 1692 case Number:1693 case RegExp:1694 case Function:1695 state = actual.toString().match(arg.toString())1695 state = actual.toString().indexOf(arg) !== -11696 break1697 1698 case Object:1699 state = arg in actual
74 unmodified lines
modified:spec/node.js+1 added-1 removed
deleted:spec/spec.helpers.js-74 removed
12describe 'Express'3 describe 'toArray()'4 describe 'when given an array'5 it 'should return the array'6 toArray([1,2,3]).should.eql [1,2,3]7 end8 end9 10 describe 'when given an object with indexed values and length'11 it 'should return an array'12 var args = -{ return arguments }('foo', 'bar')13 toArray(args).should.eql ['foo', 'bar']14 end15 end16 end17 18 describe 'escape()'19 it 'should escape html'20 escape('<p>this & that').should.eql '&lt;p&gt;this &amp; that'21 end22 end23 24 describe 'uid()'25 it 'should return a string of random characters'26 uid().should.not.eql uid()27 uid().length.should.be_greater_than 2028 end29 end30 31 describe 'extname()'32 it 'should return the a files extension'33 extname('image.png').should.eql 'png'34 extname('image.large.png').should.eql 'png'35 extname('/path/to/image.large.png').should.eql 'png'36 end37 38 it 'should return null when not found'39 extname('path').should.be_null40 extname('/just/a/path').should.be_null41 end42 end43 44 describe 'dirname()'45 it 'should return the directory path'46 dirname('/path/to/images/foo.bar.png').should.eql '/path/to/images'47 end48 end49 50 describe 'basename()'51 it 'should return a files basename'52 basename('foo/bar/baz.image.png').should.eql 'baz.image.png'53 end54 end55 56 describe 'mergeParam()'57 describe 'with empty params'58 it 'should merge the given key and value'59 params = {}60 mergeParam('user[names][first]', 'tj', params)61 params.user.names.first.should.eql 'tj'62 end63 end64 65 describe 'with populated params'66 it 'should merge not overwrite'67 params = { user: { name: 'tj' }}68 mergeParam('user[email]', 'tj@vision-media.ca', params)69 params.user.name.should.eql 'tj'70 params.user.email.should.eql 'tj@vision-media.ca'71 end72 end73 end74end
added:spec/spec.utils.js+72 added
12describe 'Express'3 before4 utils = require('express/utils')5 end6 7 describe 'toArray()'8 describe 'when given an array'9 it 'should return the array'10 utils.toArray([1,2,3]).should.eql [1,2,3]11 end12 end13 14 describe 'when given an object with indexed values and length'15 it 'should return an array'16 var args = -{ return arguments }('foo', 'bar')17 utils.toArray(args).should.eql ['foo', 'bar']18 end19 end20 end21 22 describe 'escape()'23 it 'should escape html'24 utils.escape('<p>this & that').should.eql '&lt;p&gt;this &amp; that'25 end26 end27 28 describe 'uid()'29 it 'should return a string of random characters'30 utils.uid().should.not.eql utils.uid()31 utils.uid().length.should.be_greater_than 2032 end33 end34 35 describe 'extname()'36 it 'should return the a files extension'37 utils.extname('image.png').should.eql 'png'38 utils.extname('image.large.png').should.eql 'png'39 utils.extname('/path/to/image.large.png').should.eql 'png'40 end41 42 it 'should return null when not found'43 utils.extname('path').should.be_null44 utils.extname('/just/a/path').should.be_null45 end46 end47 48 describe 'basename()'49 it 'should return a files basename'50 utils.basename('foo/bar/baz.image.png').should.eql 'baz.image.png'51 end52 end53 54 describe 'mergeParam()'55 describe 'with empty params'56 it 'should merge the given key and value'57 params = {}58 utils.mergeParam('user[names][first]', 'tj', params)59 params.user.names.first.should.eql 'tj'60 end61 end62 63 describe 'with populated params'64 it 'should merge not overwrite'65 params = { user: { name: 'tj' }}66 utils.mergeParam('user[email]', 'tj@vision-media.ca', params)67 params.user.name.should.eql 'tj'68 params.user.email.should.eql 'tj@vision-media.ca'69 end70 end71 end72end
modified:Readme.md+2 added-2 removed
56 unmodified lines
57 58 configure(function(){59 use(MethodOverride)60 use(ContentLength)61 set('root', dirname(__filename))61 set('root', __dirname)62 })63 64 get('/hello', function(){65 this.contentType('html')
37 unmodified lines
103 $ node spec/node.js routing104 ...105 106Express is currently being developed with node --version:107 v0.1.24-13-ge2abc5f107 v0.1.27108 109## More Information110111 * [JavaScript Extensions &amp; Utilities](http://github.com/visionmedia/ext.js)
34 unmodified lines