From a13b9afe752a399f25ab83d4209d6c890d1d3131 Mon Sep 17 00:00:00 2001 From: getsnoopy Date: Thu, 13 Oct 2022 01:39:37 -0500 Subject: [PATCH] Account for / routes in RestAdapter.allRoutes Previously, there was a bug in RestAdapter.allRoutes where the paths for routes which were mounted at / would return as empty instead of the expected / because of some trailing slash removal logic that was faulty. This commit fixes this so that it accounts for cases where the path itself is /, so the logic will leave those unchanged. Fixes strongloop/strong-remoting#487 --- lib/rest-adapter.js | 2 +- test/rest-adapter.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/rest-adapter.js b/lib/rest-adapter.js index eb1f48f..ac39701 100644 --- a/lib/rest-adapter.js +++ b/lib/rest-adapter.js @@ -584,7 +584,7 @@ RestAdapter.prototype.allRoutes = function() { path = currentRoot + path; } - if (path[path.length - 1] === '/') { + if (path.length > 1 && path[path.length - 1] === '/') { path = path.substr(0, path.length - 1); } diff --git a/test/rest-adapter.test.js b/test/rest-adapter.test.js index 74b9366..bb0e19b 100644 --- a/test/rest-adapter.test.js +++ b/test/rest-adapter.test.js @@ -595,6 +595,18 @@ describe('RestAdapter', function() { const allRoutes = restAdapter.allRoutes(); expect(allRoutes[0]).to.have.property('http'); }); + + it('does not alter / paths', function() { + const remotes = RemoteObjects.create({cors: false}); + remotes.exports.testClass = factory.createSharedClass(); + remotes.exports.testClass.http = {path: '/', verb: 'any'}; + remotes.exports.testClass.sharedCtor.accepts = []; + remotes.exports.testClass.sharedCtor.http = {path: '/', verb: 'patch'}; + + const restAdapter = new RestAdapter(remotes); + const allRoutes = restAdapter.allRoutes(); + expect(allRoutes[0].path).to.equal('/'); + }); }); });