From 6e5835a86c561061744260c75206b00ffac53134 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Fri, 20 May 2016 15:51:42 -0500 Subject: [PATCH] Backport PR #7257 --------- **Commit 1:** [field formatters] IP should return - on null or undefined * Original sha: 959d9cf374d3d670a883ba99465920d666331737 * Authored by Jonathan Budzenski on 2016-05-20T18:34:57Z --- src/ui/public/stringify/__tests__/_ip.js | 11 ++++++++--- src/ui/public/stringify/types/Ip.js | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ui/public/stringify/__tests__/_ip.js b/src/ui/public/stringify/__tests__/_ip.js index e8c07e9051c0..208816c08ce3 100644 --- a/src/ui/public/stringify/__tests__/_ip.js +++ b/src/ui/public/stringify/__tests__/_ip.js @@ -1,16 +1,21 @@ describe('IP Address Format', function () { - let fieldFormats; let expect = require('expect.js'); let ngMock = require('ngMock'); + let ip; beforeEach(ngMock.module('kibana')); beforeEach(ngMock.inject(function (Private) { - fieldFormats = Private(require('ui/registry/field_formats')); + const fieldFormats = Private(require('ui/registry/field_formats')); + ip = fieldFormats.getInstance('ip'); })); it('convers 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('-'); + }); + }); diff --git a/src/ui/public/stringify/types/Ip.js b/src/ui/public/stringify/types/Ip.js index 2741d44dfcb8..ca5e860f38f2 100644 --- a/src/ui/public/stringify/types/Ip.js +++ b/src/ui/public/stringify/types/Ip.js @@ -13,6 +13,7 @@ define(function (require) { Ip.fieldType = 'ip'; Ip.prototype._convert = function (val) { + if (val === undefined || val === null) return '-'; if (!isFinite(val)) return val; // shazzam!