Skip to content

Commit

Permalink
Account for / routes in RestAdapter.allRoutes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
getsnoopy committed Oct 13, 2022
1 parent baa3a5b commit a13b9af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rest-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 12 additions & 0 deletions test/rest-adapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
});
});
});

Expand Down

0 comments on commit a13b9af

Please sign in to comment.