🕷 Super-agent driven library for testing node.js HTTP servers using a fluent API. Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
MIT License
13.79k
stars
757
forks
source link
Inconsistency between express and supertest when using escaped parenthesis and single quotes in routes #669
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):
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:<port>/api/hello-one(foo) and
GET http://localhost:<port>/api/hello-two('foo')
both return the correct objects as expected.
TLDR; There seems to be some sort of inconsistency between
express
andsupertest
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 (usingmocha
to run them):The first test passes as expected. The second test fails unexpectedly, with an actual status of
404
instead of the expected200
. But in the browser (using Firefox),GET http://localhost:<port>/api/hello-one(foo)
andGET http://localhost:<port>/api/hello-two('foo')
both return the correct objects as expected.What's going on here? Any help is appreciated!