Skip to content

Commit

Permalink
Fix navigation when basePath is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed May 8, 2018
1 parent 2506398 commit d6ec0f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions x-pack/plugins/spaces/common/spaces_url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ export function stripSpaceUrlContext(basePath = '/') {
} else {
basePathWithoutSpace = basePath.substring(0, indexOfSpaceContext);
}
} else {
basePathWithoutSpace = basePath;
}

return basePathWithoutSpace;
if (basePathWithoutSpace.endsWith('/')) {
return basePathWithoutSpace.substr(0, -1);
}

return basePath;
return basePathWithoutSpace;
}
8 changes: 6 additions & 2 deletions x-pack/plugins/spaces/common/spaces_url_parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('it removes the space url context from the base path when the space is not

test('it removes the space url context from the base path when the space is the root', () => {
const basePath = `/s/my-space`;
expect(stripSpaceUrlContext(basePath)).toEqual('/');
expect(stripSpaceUrlContext(basePath)).toEqual('');
});

test(`it doesn't change base paths without a space url context`, () => {
Expand All @@ -21,7 +21,11 @@ test(`it doesn't change base paths without a space url context`, () => {
});

test('it accepts no parameters', () => {
expect(stripSpaceUrlContext()).toEqual('/');
expect(stripSpaceUrlContext()).toEqual('');
});

test('it remove the trailing slash', () => {
expect(stripSpaceUrlContext('/')).toEqual('');
});

test('it identifies the space url context', () => {
Expand Down

0 comments on commit d6ec0f6

Please sign in to comment.