Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent reuse mutated route option for head #4273

Merged
merged 3 commits into from Sep 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/route.test.js
Expand Up @@ -1464,3 +1464,32 @@ test('invalid url attribute - non string URL', t => {
t.equal(error.code, FST_ERR_INVALID_URL().code)
}
})

test('exposeHeadRoute should not reuse the same route option', async t => {
t.plan(2)

const fastify = Fastify()

// we update the onRequest hook in onRoute hook
// if we reuse the same route option
// that means we will append another function inside the array
fastify.addHook('onRoute', function (routeOption) {
if (Array.isArray(routeOption.onRequset)) {
climba03003 marked this conversation as resolved.
Show resolved Hide resolved
routeOption.onRequset.push(() => {})
} else {
routeOption.onRequset = [() => {}]
}
})

fastify.addHook('onRoute', function (routeOption) {
t.equal(routeOption.onRequset.length, 1)
})

fastify.route({
method: 'GET',
path: '/more-coffee',
async handler () {
return 'hello world'
}
})
})