Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/kibana/components/stringify/types/String.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,31 @@ define(function (require) {
{ id: false, name: '- none -' },
{ id: 'lower', name: 'Lower Case' },
{ id: 'upper', name: 'Upper Case' },
{ id: 'short', name: 'Short Dots' }
{ id: 'short', name: 'Short Dots' },
{ id: 'base64', name: 'Base64 Decode'}
];

_String.sampleInputs = [
'A Quick Brown Fox.',
'com.organizations.project.ClassName',
'hostname.net'
'hostname.net',
'SGVsbG8gd29ybGQ='
];

_String.prototype._base64Decode = function (val) {
try {
return window.atob(val);
} catch (e) {
return _.asPrettyString(val);
}
};

_String.prototype._convert = function (val) {
switch (this.param('transform')) {
case 'lower': return String(val).toLowerCase();
case 'upper': return String(val).toUpperCase();
case 'short': return _.shortenDottedString(val);
case 'base64': return this._base64Decode(val);
default: return _.asPrettyString(val);
}
};
Expand Down
19 changes: 19 additions & 0 deletions test/unit/specs/components/stringify/_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
define(function (require) {
return ['String Format', function () {
var fieldFormats;

beforeEach(module('kibana'));
beforeEach(inject(function (Private) {
fieldFormats = Private(require('registry/field_formats'));
}));

it('decode a base64 string', function () {
var StringFormat = fieldFormats.getType('string');
var string = new StringFormat({
transform: 'base64'
});
expect(string.convert('Zm9vYmFy')).to.be('foobar');
});

}];
});
1 change: 1 addition & 0 deletions test/unit/specs/components/stringify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ define(function (require) {
describe(require('specs/components/stringify/_conformance'));
describe(require('specs/components/stringify/_ip'));
describe(require('specs/components/stringify/_source'));
describe(require('specs/components/stringify/_string'));
describe(require('specs/components/stringify/_url'));
});
});