Skip to content

Commit a13b9af

Browse files
committed
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#487
1 parent baa3a5b commit a13b9af

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/rest-adapter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ RestAdapter.prototype.allRoutes = function() {
584584
path = currentRoot + path;
585585
}
586586

587-
if (path[path.length - 1] === '/') {
587+
if (path.length > 1 && path[path.length - 1] === '/') {
588588
path = path.substr(0, path.length - 1);
589589
}
590590

test/rest-adapter.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,18 @@ describe('RestAdapter', function() {
595595
const allRoutes = restAdapter.allRoutes();
596596
expect(allRoutes[0]).to.have.property('http');
597597
});
598+
599+
it('does not alter / paths', function() {
600+
const remotes = RemoteObjects.create({cors: false});
601+
remotes.exports.testClass = factory.createSharedClass();
602+
remotes.exports.testClass.http = {path: '/', verb: 'any'};
603+
remotes.exports.testClass.sharedCtor.accepts = [];
604+
remotes.exports.testClass.sharedCtor.http = {path: '/', verb: 'patch'};
605+
606+
const restAdapter = new RestAdapter(remotes);
607+
const allRoutes = restAdapter.allRoutes();
608+
expect(allRoutes[0].path).to.equal('/');
609+
});
598610
});
599611
});
600612

0 commit comments

Comments
 (0)