From d6ec0f6f5c50f9bb628e7f3e50a4fe4da3e79d17 Mon Sep 17 00:00:00 2001 From: Larry Gregory Date: Tue, 8 May 2018 15:30:10 -0400 Subject: [PATCH] Fix navigation when basePath is not set --- x-pack/plugins/spaces/common/spaces_url_parser.js | 8 ++++++-- x-pack/plugins/spaces/common/spaces_url_parser.test.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/spaces/common/spaces_url_parser.js b/x-pack/plugins/spaces/common/spaces_url_parser.js index 2bae42c28a6be2..075f09eea03a3f 100644 --- a/x-pack/plugins/spaces/common/spaces_url_parser.js +++ b/x-pack/plugins/spaces/common/spaces_url_parser.js @@ -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; } diff --git a/x-pack/plugins/spaces/common/spaces_url_parser.test.js b/x-pack/plugins/spaces/common/spaces_url_parser.test.js index 95d375f404530b..ee0813b2f70acb 100644 --- a/x-pack/plugins/spaces/common/spaces_url_parser.test.js +++ b/x-pack/plugins/spaces/common/spaces_url_parser.test.js @@ -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`, () => { @@ -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', () => {