openvibers/openvibe.shared Commits

metrics: an array route is labelled by the plain member that matched

OP OpenVibers committed 23 Sept 2026 · 31572ca653 · 2 files, +4 −1


Changes

ddiff --git a/metrics.js b/metrics.js
iindex 40a1cd2..4e9e99e 100644
---- a/metrics.js
++++ b/metrics.js
@@@ -219,7 +219,8 @@ function templatePath(p) {
function routeLabel(req) {
if (!req.route || req.route.path === undefined) return 'unmatched';
const rp = req.route.path;
-- const tail = rp instanceof RegExp ? '(regex)' : Array.isArray(rp) ? String(rp[0]) : String(rp);
++ // An array route ('/a', '/b') is labelled by the member that matched when it is a plain path.
++ const tail = rp instanceof RegExp ? '(regex)' : Array.isArray(rp) ? String(rp.find((p) => typeof p === 'string' && p === req.path) || rp[0]) : String(rp);
const base = req.baseUrl ? templatePath(req.baseUrl) : '';
const joined = `${base}${tail === '/' && base ? '' : tail}`;
return (joined || '/').slice(0, MAX_LABEL_VALUE);
ddiff --git a/test/metrics.test.js b/test/metrics.test.js
iindex 3261920..655d6c7 100644
---- a/test/metrics.test.js
++++ b/test/metrics.test.js
@@@ -62,6 +62,8 @@ const metrics = require('../metrics');
assert.strictEqual(metrics.routeLabel({ route: { path: '/' }, baseUrl: '' }), '/');
assert.strictEqual(metrics.routeLabel({ route: { path: /^\/x/ }, baseUrl: '' }), '(regex)');
assert.strictEqual(metrics.routeLabel({ route: { path: ['/a', '/b'] }, baseUrl: '' }), '/a');
++ assert.strictEqual(metrics.routeLabel({ route: { path: ['/a', '/b'] }, baseUrl: '', path: '/b' }), '/b');
++ assert.strictEqual(metrics.routeLabel({ route: { path: ['/a', '/b/:id'] }, baseUrl: '', path: '/b/7' }), '/a', 'a parameterised member never labels with the raw path');
assert.strictEqual(metrics.routeLabel({ baseUrl: '/secret/123', originalUrl: '/secret/123?q=1' }), 'unmatched');
// ── Loopback-only guard ──