fastify 3.21.4 → 3.21.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/decorate.js CHANGED
@@ -47,7 +47,7 @@ function decorateConstructor (konstructor, name, fn, dependencies) {
47
47
  get: fn.getter,
48
48
  set: fn.setter
49
49
  })
50
- } else if (fn) {
50
+ } else if (fn !== undefined && fn !== null) {
51
51
  instance[name] = fn
52
52
  } else {
53
53
  konstructor.props.push(name)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify",
3
- "version": "3.21.4",
3
+ "version": "3.21.5",
4
4
  "description": "Fast and low overhead web framework, for Node.js",
5
5
  "main": "fastify.js",
6
6
  "type": "commonjs",
@@ -939,3 +939,90 @@ test('plugin required decorators', async t => {
939
939
  app.register(plugin2)
940
940
  await app.ready()
941
941
  })
942
+
943
+ test('decorateRequest/decorateReply empty string', t => {
944
+ t.plan(7)
945
+ const fastify = Fastify()
946
+
947
+ fastify.decorateRequest('test', '')
948
+ fastify.decorateReply('test2', '')
949
+ fastify.get('/yes', (req, reply) => {
950
+ t.equal(req.test, '')
951
+ t.equal(reply.test2, '')
952
+ reply.send({ hello: 'world' })
953
+ })
954
+ t.teardown(fastify.close.bind(fastify))
955
+
956
+ fastify.listen(0, err => {
957
+ t.error(err)
958
+ fastify.server.unref()
959
+
960
+ sget({
961
+ method: 'GET',
962
+ url: 'http://localhost:' + fastify.server.address().port + '/yes'
963
+ }, (err, response, body) => {
964
+ t.error(err)
965
+ t.equal(response.statusCode, 200)
966
+ t.equal(response.headers['content-length'], '' + body.length)
967
+ t.same(JSON.parse(body), { hello: 'world' })
968
+ })
969
+ })
970
+ })
971
+
972
+ test('decorateRequest/decorateReply is undefined', t => {
973
+ t.plan(7)
974
+ const fastify = Fastify()
975
+
976
+ fastify.decorateRequest('test', undefined)
977
+ fastify.decorateReply('test2', undefined)
978
+ fastify.get('/yes', (req, reply) => {
979
+ t.equal(req.test, null)
980
+ t.equal(reply.test2, null)
981
+ reply.send({ hello: 'world' })
982
+ })
983
+ t.teardown(fastify.close.bind(fastify))
984
+
985
+ fastify.listen(0, err => {
986
+ t.error(err)
987
+ fastify.server.unref()
988
+
989
+ sget({
990
+ method: 'GET',
991
+ url: 'http://localhost:' + fastify.server.address().port + '/yes'
992
+ }, (err, response, body) => {
993
+ t.error(err)
994
+ t.equal(response.statusCode, 200)
995
+ t.equal(response.headers['content-length'], '' + body.length)
996
+ t.same(JSON.parse(body), { hello: 'world' })
997
+ })
998
+ })
999
+ })
1000
+
1001
+ test('decorateRequest/decorateReply is not set to a value', t => {
1002
+ t.plan(7)
1003
+ const fastify = Fastify()
1004
+
1005
+ fastify.decorateRequest('test')
1006
+ fastify.decorateReply('test2')
1007
+ fastify.get('/yes', (req, reply) => {
1008
+ t.equal(req.test, null)
1009
+ t.equal(reply.test2, null)
1010
+ reply.send({ hello: 'world' })
1011
+ })
1012
+ t.teardown(fastify.close.bind(fastify))
1013
+
1014
+ fastify.listen(0, err => {
1015
+ t.error(err)
1016
+ fastify.server.unref()
1017
+
1018
+ sget({
1019
+ method: 'GET',
1020
+ url: 'http://localhost:' + fastify.server.address().port + '/yes'
1021
+ }, (err, response, body) => {
1022
+ t.error(err)
1023
+ t.equal(response.statusCode, 200)
1024
+ t.equal(response.headers['content-length'], '' + body.length)
1025
+ t.same(JSON.parse(body), { hello: 'world' })
1026
+ })
1027
+ })
1028
+ })