Skip to content

Commit

Permalink
URL field formatter fix (#46332) (#47464)
Browse files Browse the repository at this point in the history
* Fix url render relative hyperlinks

* Fix test cases

* Make prefix less errorable

* Add some tests for url formatter
  • Loading branch information
sulemanof authored Oct 7, 2019
1 parent 3fe9dcc commit 2d04d70
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,29 @@ describe('UrlFormat', function () {
expect(converter('../foo/bar', null, null, parsedUrl))
.to.be('<span ng-non-bindable><a href="http://kibana.host.com/nbc/app/../foo/bar" target="_blank" rel="noopener noreferrer">../foo/bar</a></span>');
});

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('<span ng-non-bindable><a href="http://kibana.host.com/app/10.22.55.66" target="_blank" rel="noopener noreferrer">10.22.55.66</a></span>');

expect(converter('http://www.domain.name/app/kibana#/dashboard/', null, null, parsedUrl))
.to.be('<span ng-non-bindable><a href="http://www.domain.name/app/kibana#/dashboard/" target="_blank" rel="noopener noreferrer">http://www.domain.name/app/kibana#/dashboard/</a></span>');

expect(converter('/app/kibana', null, null, parsedUrl))
.to.be('<span ng-non-bindable><a href="http://kibana.host.com/app/kibana" target="_blank" rel="noopener noreferrer">/app/kibana</a></span>');

expect(converter('kibana#/dashboard/', null, null, parsedUrl))
.to.be('<span ng-non-bindable><a href="http://kibana.host.com/app/kibana#/dashboard/" target="_blank" rel="noopener noreferrer">kibana#/dashboard/</a></span>');

expect(converter('#/dashboard/', null, null, parsedUrl))
.to.be('<span ng-non-bindable><a href="http://kibana.host.com/app/kibana#/dashboard/" target="_blank" rel="noopener noreferrer">#/dashboard/</a></span>');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
}

Expand Down

0 comments on commit 2d04d70

Please sign in to comment.