openvibers/openvibe.shared Commits
metrics: an array route is labelled by the plain member that matched
Changes
@@@ -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);@@@ -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 ──
@@ -219,7 +219,8 @@ function templatePath(p) {
@@ -219,7 +219,8 @@ function templatePath(p) {
function routeLabel(req) {
function routeLabel(req) {
if (!req.route || req.route.path === undefined) return 'unmatched';
if (!req.route || req.route.path === undefined) return 'unmatched';
const rp = req.route.path;
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 base = req.baseUrl ? templatePath(req.baseUrl) : '';
const joined = `${base}${tail === '/' && base ? '' : tail}`;
const joined = `${base}${tail === '/' && base ? '' : tail}`;
return (joined || '/').slice(0, MAX_LABEL_VALUE);
return (joined || '/').slice(0, MAX_LABEL_VALUE);
@@ -62,6 +62,8 @@ const metrics = require('../metrics');
@@ -62,6 +62,8 @@ const metrics = require('../metrics');
assert.strictEqual(metrics.routeLabel({ route: { path: '/' }, baseUrl: '' }), '/');
assert.strictEqual(metrics.routeLabel({ route: { path: '/' }, baseUrl: '' }), '/');
assert.strictEqual(metrics.routeLabel({ route: { path: /^\/x/ }, baseUrl: '' }), '(regex)');
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: '' }), '/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');
assert.strictEqual(metrics.routeLabel({ baseUrl: '/secret/123', originalUrl: '/secret/123?q=1' }), 'unmatched');
// ── Loopback-only guard ──
// ── Loopback-only guard ──