forwardemail / forwardemail/supertest
Inconsistency between express and supertest when using escaped parenthesis and single quotes in routes
- Dominant language
- JavaScript
- Stars
- 14.4k
- Forks
- 782
- PR merge metrics
- No merged PRs in 30d
Description
> express version: 4.17.1
> supertest version: 4.0.2
TLDR; There seems to be some sort of inconsistency between `express` and `supertest` when handling routes with single quotes. Or I'm missing something trivial.
I have two `express` routes. I'm escaping parenthesis in the routes with `\\` as suggested in the docs.
`app.get('/api/hello-one\\(:msg\\)', (req, res) => res.send({ num: 1, msg: req.params.msg }));`
`app.get('/api/hello-two\\(\':msg\'\\)', (req, res) => res.send({ num: 2, msg: req.params.msg }));`
I have two `supertest` tests (using `mocha` to run them):
> it('should return correct response for hello-one', (done) => {
> const app = createExpressApp(null);
> console.log(app._router.stack);
> request(app).get(\`/api/hello-one('foo')\`).expect(200).expect({ num: 1, msg: \`'foo'\`}, done);
> });
>
> it('should return correct response for hello-two', (done) => {
> const app = createExpressApp(null);
> console.log(app._router.stack);
> request(app).get(\`/api/hello-two('foo')\`).expect(200).expect({ num: 2, msg: \`foo\`}, done);
> });
The first test passes as expected.
The second test fails unexpectedly, with an actual status of `404` instead of the expected `200`.
But in the *browser* (using Firefox),
`GET http://localhost:/api/hello-one(foo)` and
`GET http://localhost:/api/hello-two('foo')`
both return the correct objects as expected.
What's going on here? Any help is appreciated!
Contributor guide
Assessment
This issue has not been assessed yet.