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
Provenance
- Commit
cec6770- Tree
f1a43e5- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent 1
327d5b0- Parent 2
7e92012
13 files changed+258 added−243 removed
modified:examples/chat/app.js+5 added-4 removed
9 unmodified lines101112131414151617181919202122232410 unmodified lines3536373838394041424310 unmodified lines5455565757585960616219 unmodified lines9 unmodified lines use(ContentLength) use(CommonLogger) use(Cookie) use(Session, { lifetime: fiveMinutes, reapInterval: oneMinute }) set('root', dirname(__filename)) set('root', __dirname) enable('cache static files') //enable('cache view contents')})
var messages = []var messages = [], utils = require('express/utils') get('/', function(){ this.redirect('/chat')})10 unmodified lines
post('/chat', function(){ this.session.name = this.param('name') messages .push(escape(this.param('name')) + ': ' + escape(this.param('message')) .push(utils.escape(this.param('name')) + ': ' + utils.escape(this.param('message')) .replace(/(http:\/\/[^\s]+)/g, '<a href="$1" target="express-chat">$1</a>') .replace(/:\)/g, '<img src="http://icons3.iconfinder.netdna-cdn.com/data/icons/ledicons/emoticon_smile.png">')) this.halt(200)})10 unmodified lines }, 100)})
get('/public/*', function(file){ this.sendfile(dirname(__filename) + '/public/' + file) this.sendfile(__dirname + '/public/' + file)})
get('/*.css', function(file){ this.render(file + '.sass.css', { layout: false })19 unmodified linesmodified:examples/upload/app.js+2 added-2 removed
5 unmodified lines678910101112131411 unmodified lines262728293030313233343 unmodified lines5 unmodified linesconfigure(function(){ use(MethodOverride) use(ContentLength) use(CommonLogger) set('root', dirname(__filename)) set('root', __dirname) enable('cache view contents')})
get('/', function(){11 unmodified lines this.redirect('/upload')})
get('/public/*', function(file){ this.sendfile(dirname(__filename) + '/public/' + file) this.sendfile(__dirname + '/public/' + file)})
get('/*.css', function(file){ this.render(file + '.sass.css', { layout: false })3 unmodified linesmodified:lib/express/plugins/view.js+3 added-2 removed
3 unmodified lines4 /**5 * Module dependencies.6 */7 8-var posix = require('posix')8+var posix = require('posix'),9+ utils = require('express/utils')10 11 /**12 * Supported template engines.13 */51 unmodified lines65 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 linesmodified:lib/express/core.js+28 added-11 removed
4 unmodified lines5 process.mixin(require('express/exceptions'))6 process.mixin(require('express/collection'))7 process.mixin(require('express/event'))8 process.mixin(require('express/request'))9-process.mixin(require('express/helpers'))9 process.mixin(require('express/plugin'))10 process.mixin(require('express/mime'))11 process.mixin(require('express/dsl'))12 13+/**14+ * Module dependencies.15+ */16+17 var multipart = require('multipart'),15- File = require('file').File18+ File = require('file').File,19+ utils = require('express/utils')20 21 // --- Route22 23 Route = Class({59 unmodified lines83 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 lines222 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 linesdeleted:lib/express/helpers.js-135 removed
1-2-// Express - Helpers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3-4-/**5- * JSON aliases.6- */7-8-JSON.encode = JSON.stringify9-JSON.decode = JSON.parse10-11-/**12- * Return a unique identifier.13- *14- * @return {string}15- * @api public16- */17-18-exports.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-}24-25-/**26- * Return the directory name of the given _path_.27- *28- * @param {string} path29- * @return {string}30- * @api public31- */32-33-exports.dirname = function(path) {34- return path.split('/').slice(0, -1).join('/')35-}36-37-/**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- */45-46-exports.extname = function(path) {47- if (path.lastIndexOf('.') < 0) return48- return path.slice(path.lastIndexOf('.') + 1)49-}50-51-/**52- * Return the basename of the given _path_.53- *54- * @param {string} path55- * @return {string}56- * @api public57- */58-59-exports.basename = function(path) {60- return path.split('/').slice(-1)[0]61-}62-63-/**64- * Escape special characters in _html_.65- *66- * @param {string} html67- * @return {string}68- * @api public69- */70-71-exports.escape = function(html) {72- return html.toString()73- .replace(/&/g, '&')74- .replace(/"/g, '"')75- .replace(/</g, '<')76- .replace(/>/g, '>')77-}78-79-/**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- */88-89-exports.toArray = function(arr, offset) {90- return Array.prototype.slice.call(arr, offset)91-}92-93-/**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- */105-106-exports.escapeRegexp = function(string, chars) {107- var specials = (chars || '/ . * + ? | ( ) [ ] { } \\').split(' ').join('|\\')108- return string.replace(new RegExp('(\\' + specials + ')', 'g'), '\\$1')109-}110-111-/**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- */125-126-exports.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
1 2 // Express - Mime - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4-var types = {4+/**5+ * Module dependencies.6+ */7+ 8+var utils = require('express/utils')9+10+/**11+ * Mime type lookup table.12+ */13+14+exports.types = {15 '323' : 'text/h323',16 '3gp' : 'video/3gpp',17 'a' : 'application/octet-stream',18 'acx' : 'application/internet-property-stream',342 unmodified lines361 * @api public362 */363 364 exports.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
1+2+// Express - Helpers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3+4+/**5+ * JSON aliases.6+ */7+8+JSON.encode = JSON.stringify9+JSON.decode = JSON.parse10+11+/**12+ * Return a unique identifier.13+ *14+ * @return {string}15+ * @api public16+ */17+18+exports.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+}24+25+/**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+ */33+34+exports.extname = function(path) {35+ if (path.lastIndexOf('.') < 0) return36+ return path.slice(path.lastIndexOf('.') + 1)37+}38+39+/**40+ * Return the basename of the given _path_.41+ *42+ * @param {string} path43+ * @return {string}44+ * @api public45+ */46+47+exports.basename = function(path) {48+ return path.split('/').slice(-1)[0]49+}50+51+/**52+ * Escape special characters in _html_.53+ *54+ * @param {string} html55+ * @return {string}56+ * @api public57+ */58+59+exports.escape = function(html) {60+ return html.toString()61+ .replace(/&/g, '&')62+ .replace(/"/g, '"')63+ .replace(/</g, '<')64+ .replace(/>/g, '>')65+}66+67+/**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+ */76+77+exports.toArray = function(arr, offset) {78+ return Array.prototype.slice.call(arr, offset)79+}80+81+/**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+ */93+94+exports.escapeRegexp = function(string, chars) {95+ var specials = (chars || '/ . * + ? | ( ) [ ] { } \\').split(' ').join('|\\')96+ return string.replace(new RegExp('(\\' + specials + ')', 'g'), '\\$1')97+}98+99+/**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+ */113+114+exports.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
123456345678
var path = require('path')require.paths.unshift(path.dirname(__filename) + '/support/js-oo/lib')require.paths.unshift(path.dirname(__filename) + '/support/ejs/lib')require.paths.unshift(path.dirname(__filename) + '/support/haml/lib')require.paths.unshift(path.dirname(__filename) + '/support/sass/lib')require.paths.unshift(__dirname + '/support/js-oo/lib')require.paths.unshift(__dirname + '/support/ejs/lib')require.paths.unshift(__dirname + '/support/haml/lib')require.paths.unshift(__dirname + '/support/sass/lib')require('oo')require('express/core')No newline at end of fileNo newline at end of filemodified:spec/lib/jspec.js+5 added-5 removed
2 unmodified lines3 4 ;(function(){5 6 JSpec = {7- version : '3.1.0',7+ version : '3.2.1',8 assert : true,9 cache : {},10 suites : [],11 modules : [],1033 unmodified lines1045 * @api public1046 */1047 1048 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 line1055 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 lines1691 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 actual74 unmodified linesmodified:spec/node.js+1 added-1 removed
25 unmodified lines2627282930303132333433 unmodified lines25 unmodified linesspecs = { independant: [ 'core', 'routing', 'helpers', 'utils', 'request', 'mime', 'static', 'collection',33 unmodified linesdeleted:spec/spec.helpers.js-74 removed
1-2-describe '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 '<p>this & 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- end74-endadded:spec/spec.utils.js+72 added
1+2+describe '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 '<p>this & 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+ end72+endmodified:Readme.md+2 added-2 removed
56 unmodified lines57 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 lines103 $ node spec/node.js routing104 ...105 106 Express is currently being developed with node --version:107- v0.1.24-13-ge2abc5f107+ v0.1.27108 109 ## More Information110 111 * [JavaScript Extensions & Utilities](http://github.com/visionmedia/ext.js)34 unmodified lines