diff --git a/src/legacy/core_plugins/kibana/common/field_formats/types/__tests__/url.js b/src/legacy/core_plugins/kibana/common/field_formats/types/__tests__/url.js index 16895d9e25a8d..4f7a6f4ebe82f 100644 --- a/src/legacy/core_plugins/kibana/common/field_formats/types/__tests__/url.js +++ b/src/legacy/core_plugins/kibana/common/field_formats/types/__tests__/url.js @@ -189,5 +189,29 @@ describe('UrlFormat', function () { expect(converter('../foo/bar', null, null, parsedUrl)) .to.be('../foo/bar'); }); + + it('should support multiple types of urls w/o basePath', function () { + const url = new UrlFormat(); + const parsedUrl = { + origin: 'http://kibana.host.com', + pathname: '/app/kibana', + }; + const converter = url.getConverterFor('html'); + + expect(converter('10.22.55.66', null, null, parsedUrl)) + .to.be('10.22.55.66'); + + expect(converter('http://www.domain.name/app/kibana#/dashboard/', null, null, parsedUrl)) + .to.be('http://www.domain.name/app/kibana#/dashboard/'); + + expect(converter('/app/kibana', null, null, parsedUrl)) + .to.be('/app/kibana'); + + expect(converter('kibana#/dashboard/', null, null, parsedUrl)) + .to.be('kibana#/dashboard/'); + + expect(converter('#/dashboard/', null, null, parsedUrl)) + .to.be('#/dashboard/'); + }); }); }); diff --git a/src/legacy/core_plugins/kibana/common/field_formats/types/url.js b/src/legacy/core_plugins/kibana/common/field_formats/types/url.js index 4058ef61bbeb6..0b65e103d20ea 100644 --- a/src/legacy/core_plugins/kibana/common/field_formats/types/url.js +++ b/src/legacy/core_plugins/kibana/common/field_formats/types/url.js @@ -157,7 +157,9 @@ export function createUrlFormat(FieldFormat) { } // Handle urls like: `../app/kibana` else { - prefix = `${parsedUrl.origin}${parsedUrl.basePath}/app/`; + const prefixEnd = url[0] === '/' ? '' : '/'; + + prefix = `${parsedUrl.origin}${parsedUrl.basePath || ''}/app${prefixEnd}`; } }