Merge branch 'master' of github.com:visionmedia/express
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parents 4a1fa58, 771573b · Browse files · 7 files·+117 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+117 added−17 removed
- tests:+106 added−8 removed
- other:+11 added−9 removed
Provenance
- Commit
c6d7352- Tree
921bb97- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent 1
4a1fa58- Parent 2
771573b
7 files changed+117 added−17 removed
modified:lib/response.js+5 added-3 removed
632 unmodified lines633 url = map[url] || url;634 635 // relative636 if (!~url.indexOf('://') && 0 != url.indexOf('//')) {637- var path = app.path();637+ var path638 639 // relative to path640 if ('.' == url[0]) {641+ path = req.originalUrl.split('?')[0]641- url = req.path + '/' + url;642- // relative to mount-point642+ url = path + ('/' == path[path.length - 1] ? '' : '/') + url;643+ // relative to mount-point644 } else if ('/' != url[0]) {645+ path = app.path();646 url = path + '/' + url;647 }648 }649 107 unmodified linesmodified:lib/utils.js+2 added-2 removed
18 unmodified lines19 };20 21 /**22 * Make `locals()` bound to the given `obj`.23- * 24- * This is used for `app.locals` and `res.locals`. 23 *24+ * This is used for `app.locals` and `res.locals`.25+ *26 * @param {Object} obj27 * @return {Function}28 * @api private29 */251 unmodified linesmodified:lib/view.js+4 added-4 removed
6 unmodified lines789101111121314155 unmodified lines212223242526272526272829303145 unmodified lines6 unmodified lines , utils = require('./utils') , dirname = path.dirname , basename = path.basename , extname = path.extname , exists = fs.existsSync || path.existsSync , exists = fs.existsSync || path.existsSync , join = path.join;
/** * Expose `View`.5 unmodified lines * Initialize a new `View` with the given `name`. * * Options: * * - `defaultEngine` the default template engine name * - `engines` template engine require() cache * - `root` root path for view lookup * - `defaultEngine` the default template engine name * - `engines` template engine require() cache * - `root` root path for view lookup * * @param {String} name * @param {Object} options * @api private45 unmodified linesmodified:test/req.accepts.js+2 added-2 removed
13 unmodified lines14 request(app)15 .get('/')16 .expect('yes', done);17 })18- 18+19 it('should return true when present', function(done){20 var app = express();21 22 app.use(function(req, res, next){4 unmodified lines27 .get('/')28 .set('Accept', 'application/json')29 .expect('yes', done);30 })31- 31+32 it('should return false otherwise', function(done){33 var app = express();34 35 app.use(function(req, res, next){89 unmodified linesmodified:test/req.acceptsCharset.js+2 added-2 removed
15 unmodified lines161718192020212223245 unmodified lines3031323334343536373811 unmodified lines15 unmodified lines .get('/') .expect('yes', done); }) })
describe('when Accept-Charset is not present', function(){ it('should return true when present', function(done){ var app = express();
5 unmodified lines .get('/') .set('Accept-Charset', 'foo, bar, utf-8') .expect('yes', done); })
it('should return false otherwise', function(done){ var app = express();
app.use(function(req, res, next){11 unmodified linesmodified:test/req.signedCookies.js+10 added-2 removed
7 unmodified lines89101112131415161718192 unmodified lines222324252226272829303 unmodified lines3435363738394041424344452 unmodified lines484950514452535455564 unmodified lines7 unmodified lines var app = express() , cookieHeader , val;
/* So we use the same serialization for expected results. */ var replacer = app.get('json replacer') , spaces = app.get('json spaces');
app.use(express.cookieParser('secret'));
app.use(function(req, res){ res.send(req.signedCookies);2 unmodified lines app.response.req = { secret: 'secret' }; app.response.cookie('obj', { foo: 'bar' }, { signed: true }); cookieHeader = app.response.get('set-cookie');
val = JSON.stringify({ obj: { foo: 'bar' } }); val = JSON.stringify({ obj: { foo: 'bar' } }, replacer, spaces); request(app) .get('/') .set('Cookie', cookieHeader) .expect(val, done);3 unmodified lines var app = express() , cookieHeader , val;
/* So we use the same serialization for expected results. */ var replacer = app.get('json replacer') , spaces = app.get('json spaces');
app.use(express.cookieParser('secret'));
app.use(function(req, res){ res.send(req.signedCookies);2 unmodified lines app.response.req = { secret: 'secret' }; app.response.cookie('foo', 'bar', { signed: true }); cookieHeader = app.response.get('set-cookie');
val = JSON.stringify({ foo: 'bar' }); val = JSON.stringify({ foo: 'bar' }, replacer, spaces); request(app) .get('/') .set('Cookie', cookieHeader) .expect(val, done);4 unmodified linesmodified:test/res.redirect.js+92 added-2 removed
72 unmodified lines73 done();74 })75 })76 })77- 77+78 describe('when accepting html', function(){79 it('should respond with html', function(done){80 var app = express();81 27 unmodified lines109 done();110 })111 })112 })113- 113+114 describe('when accepting text', function(){115 it('should respond with text', function(done){116 var app = express();117 50 unmodified lines168 done();169 })170 })171 })172+173+ describe('responses redirected to dotted relative paths', function () {174+175+ /* The requisite test fixtures are repetitive. */176+ var makeApp = function (depth, parent) {177+ var app = express();178+179+ if (parent) {180+ parent.use('/depth' + depth, app);181+ }182+183+ app.get('/', function (req, res) {184+ res.redirect('./index');185+ });186+187+ app.get('/index', function (req, res) {188+ res.json({depth : depth, content : 'index'});189+ });190+191+ return app;192+ }193+194+ var root = makeApp(0);195+ var depth1 = makeApp(1, root);196+ var depth2 = makeApp(2, depth1);197+ var depth3 = makeApp(3, depth2);198+199+ /* Special cases for alias paths. */200+ root.use('/depth2', depth2);201+ root.use('/depth3', depth3);202+203+ /*204+ * The resulting structure resembles the following.205+ *206+ * / -> root207+ *208+ * /depth1 -> depth1209+ * /depth1/depth2 -> depth2210+ * /depth1/depth2/depth3 -> depth3211+ *212+ * /depth2 -> depth2213+ * /depth3 -> depth3214+ */215+216+ it('should not contain redundant leading slashes in the location header', function (done) {217+ request(root)218+ .get('/')219+ .end(function (err, res) {220+ res.headers.location.search(/^\/{2}/).should.equal(-1);221+ done();222+ })223+ })224+225+ it('should preserve context when redirecting nested applications at any depth', function(done){226+ request(root)227+ .get('/depth1')228+ .end(function(err, res) {229+ res.headers.should.have.property('location', '/depth1/./index');230+ });231+232+ request(root)233+ .get('/depth1/depth2')234+ .end(function(err, res) {235+ res.headers.should.have.property('location', '/depth1/depth2/./index');236+ })237+238+ request(root)239+ .get('/depth1/depth2/depth3')240+ .end(function(err, res) {241+ res.headers.should.have.property('location', '/depth1/depth2/depth3/./index');242+ done();243+ })244+ })245+246+ it('should redirect correctly for nested applications that have been remounted', function (done) {247+ request(root)248+ .get('/depth2')249+ .end(function (err, res) {250+ res.headers.should.have.property('location', '/depth2/./index');251+ })252+253+ request(root)254+ .get('/depth3')255+ .end(function (err, res) {256+ res.headers.should.have.property('location', '/depth3/./index');257+ done();258+ })259+ })260+261+ })262 })