Inconsistency between express and supertest when using escaped parenthesis and single quotes in routes
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:<port>/api/hello-one(foo) and
GET http://localhost:<port>/api/hello-two('foo')
both return the correct objects as expected.
What's going on here? Any help is appreciated!
superagent is still using the deprecated function url.parse which is escaping single quotes. It should use new URL(url) instead.