Skip to content

Commit

Permalink
Merge pull request #7257 from jbudz/issues/7182
Browse files Browse the repository at this point in the history
[field formatters] IP should return - on null or undefined
  • Loading branch information
jbudz committed May 20, 2016
2 parents 5df51d5 + 959d9cf commit a11a86e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/ui/public/stringify/__tests__/_ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import expect from 'expect.js';
import ngMock from 'ng_mock';
import RegistryFieldFormatsProvider from 'ui/registry/field_formats';
describe('IP Address Format', function () {
let fieldFormats;

let ip;
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
fieldFormats = Private(RegistryFieldFormatsProvider);
const fieldFormats = Private(RegistryFieldFormatsProvider);
ip = fieldFormats.getInstance('ip');
}));

it('converts a value from a decimal to a string', function () {
let ip = fieldFormats.getInstance('ip');
expect(ip.convert(1186489492)).to.be('70.184.100.148');
});

it('converts null and undefined to -', function () {
expect(ip.convert(null)).to.be('-');
expect(ip.convert(undefined)).to.be('-');
});

});
1 change: 1 addition & 0 deletions src/ui/public/stringify/types/ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function IpFormatProvider(Private) {
Ip.fieldType = 'ip';

Ip.prototype._convert = function (val) {
if (val === undefined || val === null) return '-';
if (!isFinite(val)) return val;

// shazzam!
Expand Down

0 comments on commit a11a86e

Please sign in to comment.