Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Fix bug trailing slash to the prefix #4

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/libs/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,10 @@ export class MockoonServer extends (EventEmitter as new () => TypedEmitter<
// only launch non duplicated routes, or ignore if none.
if (declaredRoute.enabled) {
try {
const routePath =
'/' +
(this.environment.endpointPrefix
? this.environment.endpointPrefix + '/'
: '') +
declaredRoute.endpoint.replace(/ /g, '%20');
let routePath = `/${
this.environment.endpointPrefix
}/${declaredRoute.endpoint.replace(/ /g, '%20')}`;
routePath = routePath.replace('//', '');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@255kb I think this should be

routePath = routePath.replace('//', '/')

Otherwise, double slashes get completely removed. Apart from that, I think this is not the best solution as it would not solve cases where there are tripple slashes and especially, it only replaces the first occurrence of a double slash and not all.

I suggest the following:

routePath = routePath.replace(/\/\/+/g, '/');

Copy link
Member

@255kb 255kb May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True for the triple slashes, but the replace was fixed after the PR merge.


// create route
server[declaredRoute.method](
Expand Down