Skip to content

Commit 5ae1966

Browse files
tlhunterStephen Belanger
authored andcommitted
express: recognize regex with flags (#3301)
1 parent 25579aa commit 5ae1966

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

packages/datadog-plugin-express/test/index.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,42 @@ describe('Plugin', () => {
741741
})
742742
})
743743

744+
it('should work with regex having flags', done => {
745+
const app = express()
746+
747+
try {
748+
app.use(/\/foo\/(bar|baz|bez)/i, (req, res, next) => {
749+
next()
750+
})
751+
} catch (err) {
752+
// eslint-disable-next-line no-console
753+
console.log('This version of Express (>4.0 <4.6) has broken support for regex routing. Skipping this test.')
754+
this.skip && this.skip() // mocha allows dynamic skipping, tap does not
755+
return done()
756+
}
757+
758+
app.get('/foo/bar', (req, res) => {
759+
res.status(200).send('')
760+
})
761+
762+
getPort().then(port => {
763+
agent
764+
.use(traces => {
765+
const spans = sort(traces[0])
766+
767+
expect(spans[0]).to.have.property('resource', 'GET /foo/bar')
768+
})
769+
.then(done)
770+
.catch(done)
771+
772+
appListener = app.listen(port, 'localhost', () => {
773+
axios
774+
.get(`http://localhost:${port}/foo/bar`)
775+
.catch(done)
776+
})
777+
})
778+
})
779+
744780
it('long regex child of string router should not steal path', done => {
745781
const app = express()
746782
const router = express.Router()

packages/datadog-plugin-router/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function isMoreSpecificThan (routeA, routeB) {
156156
}
157157

158158
function routeIsRegex (route) {
159-
return route.includes('(/') && route.includes('/)')
159+
return route.includes('(/')
160160
}
161161

162162
module.exports = RouterPlugin

0 commit comments

Comments
 (0)