mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
parent
0766ab2381
commit
cc87c6ba93
3 changed files with 8 additions and 50 deletions
|
@ -19,9 +19,9 @@ describe('UrlFormat', function () {
|
|||
|
||||
describe('url template', function () {
|
||||
it('accepts a template', function () {
|
||||
const url = new UrlFormat({ urlTemplate: 'http://{{ value }}' });
|
||||
const url = new UrlFormat({ urlTemplate: 'url: {{ value }}' });
|
||||
expect(url.convert('url', 'html'))
|
||||
.to.be('<span ng-non-bindable><a href="http://url" target="_blank">http://url</a></span>');
|
||||
.to.be('<span ng-non-bindable><a href="url: url" target="_blank">url: url</a></span>');
|
||||
});
|
||||
|
||||
it('only outputs the url if the contentType === "text"', function () {
|
||||
|
@ -32,9 +32,9 @@ describe('UrlFormat', function () {
|
|||
|
||||
describe('label template', function () {
|
||||
it('accepts a template', function () {
|
||||
const url = new UrlFormat({ labelTemplate: 'extension: {{ value }}', urlTemplate: 'http://www.{{value}}.com' });
|
||||
const url = new UrlFormat({ labelTemplate: 'extension: {{ value }}' });
|
||||
expect(url.convert('php', 'html'))
|
||||
.to.be('<span ng-non-bindable><a href="http://www.php.com" target="_blank">extension: php</a></span>');
|
||||
.to.be('<span ng-non-bindable><a href="php" target="_blank">extension: php</a></span>');
|
||||
});
|
||||
|
||||
it('uses the label template for text formating', function () {
|
||||
|
@ -76,22 +76,4 @@ describe('UrlFormat', function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('whitelist', function () {
|
||||
it('should spit out the raw value if the value is not in the whitelist', function () {
|
||||
const url = new UrlFormat();
|
||||
|
||||
expect(url.convert('www.elastic.co', 'html'))
|
||||
.to.be('<span ng-non-bindable>www.elastic.co</span>');
|
||||
|
||||
expect(url.convert('elastic.co', 'html'))
|
||||
.to.be('<span ng-non-bindable>elastic.co</span>');
|
||||
|
||||
expect(url.convert('elastic', 'html'))
|
||||
.to.be('<span ng-non-bindable>elastic</span>');
|
||||
|
||||
expect(url.convert('ftp://elastic.co', 'html'))
|
||||
.to.be('<span ng-non-bindable>ftp://elastic.co</span>');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,7 +3,6 @@ import { FieldFormat } from '../../../../../ui/field_formats/field_format';
|
|||
import { getHighlightHtml } from '../../highlight/highlight_html';
|
||||
|
||||
const templateMatchRE = /{{([\s\S]+?)}}/g;
|
||||
const whitelistUrlSchemes = ['http://', 'https://'];
|
||||
|
||||
export class UrlFormat extends FieldFormat {
|
||||
constructor(params) {
|
||||
|
@ -99,11 +98,6 @@ UrlFormat.prototype._convert = {
|
|||
|
||||
return `<img src="${url}" alt="${imageLabel}">`;
|
||||
default:
|
||||
const inWhitelist = whitelistUrlSchemes.some(scheme => url.indexOf(scheme) === 0);
|
||||
if (!inWhitelist) {
|
||||
return url;
|
||||
}
|
||||
|
||||
let linkLabel;
|
||||
|
||||
if (hit && hit.highlight && hit.highlight[field.name]) {
|
||||
|
|
|
@ -44,11 +44,11 @@ describe('Url Format', function () {
|
|||
|
||||
describe('url template', function () {
|
||||
it('accepts a template', function () {
|
||||
const url = new Url({ urlTemplate: 'http://{{ value }}' });
|
||||
const url = new Url({ urlTemplate: 'url: {{ value }}' });
|
||||
const $a = unwrap($(url.convert('url', 'html')));
|
||||
expect($a.is('a')).to.be(true);
|
||||
expect($a.size()).to.be(1);
|
||||
expect($a.attr('href')).to.be('http://url');
|
||||
expect($a.attr('href')).to.be('url: url');
|
||||
expect($a.attr('target')).to.be('_blank');
|
||||
expect($a.children().size()).to.be(0);
|
||||
});
|
||||
|
@ -61,11 +61,11 @@ describe('Url Format', function () {
|
|||
|
||||
describe('label template', function () {
|
||||
it('accepts a template', function () {
|
||||
const url = new Url({ labelTemplate: 'extension: {{ value }}', urlTemplate: 'http://www.{{value}}.com' });
|
||||
const url = new Url({ labelTemplate: 'extension: {{ value }}' });
|
||||
const $a = unwrap($(url.convert('php', 'html')));
|
||||
expect($a.is('a')).to.be(true);
|
||||
expect($a.size()).to.be(1);
|
||||
expect($a.attr('href')).to.be('http://www.php.com');
|
||||
expect($a.attr('href')).to.be('php');
|
||||
expect($a.html()).to.be('extension: php');
|
||||
});
|
||||
|
||||
|
@ -109,23 +109,5 @@ describe('Url Format', function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('whitelist', function () {
|
||||
it('should spit out the raw value if the value is not in the whitelist', function () {
|
||||
const url = new Url();
|
||||
|
||||
expect(url.convert('www.elastic.co', 'html'))
|
||||
.to.be('<span ng-non-bindable>www.elastic.co</span>');
|
||||
|
||||
expect(url.convert('elastic.co', 'html'))
|
||||
.to.be('<span ng-non-bindable>elastic.co</span>');
|
||||
|
||||
expect(url.convert('elastic', 'html'))
|
||||
.to.be('<span ng-non-bindable>elastic</span>');
|
||||
|
||||
expect(url.convert('ftp://elastic.co', 'html'))
|
||||
.to.be('<span ng-non-bindable>ftp://elastic.co</span>');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue