@fastify/express 4.0.3 → 4.0.4

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/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  const fp = require('fastify-plugin')
4
4
  const Express = require('express')
5
- const FindMyWay = require('find-my-way')
6
5
  const kMiddlewares = Symbol('fastify-express-middlewares')
7
6
 
8
7
  function fastifyExpress (fastify, options, next) {
@@ -43,9 +42,7 @@ function fastifyExpress (fastify, options, next) {
43
42
 
44
43
  const { url } = req.raw
45
44
 
46
- const decodedUrl = FindMyWay.sanitizeUrlPath(url)
47
- // Decode URL before Express matches middleware to prevent encoded path bypass
48
- // e.g., /%61dmin should match middleware registered on /admin
45
+ const decodedUrl = decodeURI(url)
49
46
  req.raw.url = decodedUrl
50
47
  req.raw.originalUrl = url
51
48
  req.raw.id = req.id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastify/express",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "description": "Express compatibility layer for Fastify",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -76,8 +76,7 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "express": "^4.18.3",
79
- "fastify-plugin": "^5.0.0",
80
- "find-my-way": "^9.4.0"
79
+ "fastify-plugin": "^5.0.0"
81
80
  },
82
81
  "tsd": {
83
82
  "directory": "test/types"
@@ -56,6 +56,26 @@ test('trust proxy protocol', async (t) => {
56
56
  })
57
57
  })
58
58
 
59
+ test('query params still in in the request url after decodeURI', async (t) => {
60
+ t.plan(2)
61
+ const fastify = Fastify()
62
+
63
+ t.after(() => fastify.close())
64
+
65
+ fastify.register(expressPlugin).after(() => {
66
+ fastify.use('/admin', function (req, res) {
67
+ t.assert.deepStrictEqual(req.originalUrl, '/%61dmin?test=%76alue&test2=%76alue', 'originalUrl is not decoded')
68
+ t.assert.deepStrictEqual(req.url, '/admin?test=value&test2=value', 'url is decoded')
69
+
70
+ res.sendStatus(200)
71
+ })
72
+ })
73
+
74
+ const address = await fastify.listen({ port: 0 })
75
+
76
+ await fetch(`${address}/%61dmin?test=%76alue&test2=%76alue`)
77
+ })
78
+
59
79
  test('passing createProxyHandler sets up a Proxy with Express req', async t => {
60
80
  t.plan(6)
61
81
  const testString = 'test proxy'
@@ -75,7 +75,8 @@ test('POST request with form body and without body-parser works', async t => {
75
75
  })
76
76
 
77
77
  test('POST request with form body and body-parser hangs up', async t => {
78
- t.plan(2)
78
+ t.plan(3)
79
+
79
80
  const fastify = Fastify()
80
81
  const express = Express()
81
82
  t.after(() => fastify.close())
@@ -85,24 +86,25 @@ test('POST request with form body and body-parser hangs up', async t => {
85
86
  .after(() => {
86
87
  express.use(bodyParser.urlencoded({ extended: false }))
87
88
  fastify.use(express)
88
- fastify.use((req, _res, next) => {
89
- // body-parser result
90
- t.assert.deepStrictEqual(req.body, { input: 'test' })
91
- next()
92
- })
93
- })
94
89
 
95
- fastify.post('/hello', () => {
96
- return { hello: 'world' }
97
- })
90
+ fastify.use((_req, _res, next) => next())
91
+ })
98
92
 
93
+ fastify.post('/hello', () => ({ hello: 'world' }))
99
94
  const address = await fastify.listen({ port: 0 })
100
95
 
101
- await t.assert.rejects(() => fetch(address + '/hello', {
102
- method: 'post',
103
- body: new URLSearchParams({ input: 'test' }),
104
- signal: AbortSignal.timeout(5)
105
- }), 'Request timed out')
96
+ await t.assert.rejects(
97
+ () => fetch(address + '/hello', {
98
+ method: 'post',
99
+ body: new URLSearchParams({ input: 'test' }),
100
+ signal: AbortSignal.timeout(200)
101
+ }),
102
+ (err) => {
103
+ t.assert.equal(err?.name, 'TimeoutError')
104
+ t.assert.ok(err)
105
+ return true
106
+ }
107
+ )
106
108
  })
107
109
 
108
110
  test('POST request with form body and body-parser hangs up, compatibility case', async t => {