req.query.js
This file
Path
test/req.query.js
106 lines · 2.6 KiB · JavaScript
Last changed by
fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
History of this fileTake it
The walk stopped after 200 commits: lines older than 6aa4a45 point at it.
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 1why, one step back1'use strict'Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
line 2why, one step back2fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 3why, one step back3var assert = require('node:assert')Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
lines 4–16why, one step back4var express = require('../')5 , request = require('supertest');67describe('req', function(){8 describe('.query', function(){9 it('should default to {}', function(done){10 var app = createApp();1112 request(app)13 .get('/')14 .expect(200, '{}', done);15 });16Change query parser setting default to 'simple'Czarekbefore adoption450c468
line 17why, one step back17 it('should default to parse simple keys', function (done) {Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
lines 18–21why, one step back18 var app = createApp();1920 request(app)21 .get('/?user[name]=tj')Change query parser setting default to 'simple'Czarekbefore adoption450c468
line 22why, one step back22 .expect(200, '{"user[name]":"tj"}', done);Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
lines 23–29why, one step back23 });2425 describe('when "query parser" is extended', function () {26 it('should parse complex keys', function (done) {27 var app = createApp('extended');2829 request(app)Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
lines 30–31why, one step back30 .get('/?foo[0][bar]=baz&foo[0][fizz]=buzz&foo[]=done!')31 .expect(200, '{"foo":[{"bar":"baz","fizz":"buzz"},"done!"]}', done);Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
line 32why, one step back32 });Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 33–40why, one step back3334 it('should parse parameters with dots', function (done) {35 var app = createApp('extended');3637 request(app)38 .get('/?user.name=tj')39 .expect(200, '{"user.name":"tj"}', done);40 });Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
lines 41–47why, one step back41 });4243 describe('when "query parser" is simple', function () {44 it('should not parse complex keys', function (done) {45 var app = createApp('simple');4647 request(app)Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
line 48why, one step back48 .get('/?user%5Bname%5D=tj')Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
lines 49–59why, one step back49 .expect(200, '{"user[name]":"tj"}', done);50 });51 });5253 describe('when "query parser" is a function', function () {54 it('should parse using function', function (done) {55 var app = createApp(function (str) {56 return {'length': (str || '').length};57 });5859 request(app)Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
line 60why, one step back60 .get('/?user%5Bname%5D=tj')Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
lines 61–69why, one step back61 .expect(200, '{"length":17}', done);62 });63 });6465 describe('when "query parser" disabled', function () {66 it('should not parse query', function (done) {67 var app = createApp(false);6869 request(app)Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
line 70why, one step back70 .get('/?user%5Bname%5D=tj')Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
lines 71–74why, one step back71 .expect(200, '{}', done);72 });73 });74Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
line 75why, one step back75 describe('when "query parser" enabled', function () {Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
lines 76–79why, one step back76 it('should not parse complex keys', function (done) {77 var app = createApp(true);7879 request(app)Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
line 80why, one step back80 .get('/?user%5Bname%5D=tj')Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
lines 81–86why, one step back81 .expect(200, '{"user[name]":"tj"}', done);82 });83 });8485 describe('when "query parser" an unknown value', function () {86 it('should throw', function () {Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 87–88why, one step back87 assert.throws(createApp.bind(null, 'bogus'),88 /unknown value.*query parser/)Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45
lines 89–106why, one step back89 });90 });91 })92})9394function createApp(setting) {95 var app = express();9697 if (setting !== undefined) {98 app.set('query parser', setting);99 }100101 app.use(function (req, res) {102 res.send(req.query);103 });104105 return app;106}