Fix issue where non-strings were getting passed in to escape functions for handling special characters that can appear in xml. Add tests.

This commit is contained in:
Karishma Chadha 2019-02-07 11:58:10 -05:00
parent 765f2b2549
commit c761a9c82e
4 changed files with 88 additions and 2 deletions

View file

@ -109,3 +109,21 @@ test('replaceUnsafeChars', t => {
t.end();
});
test('replaceUnsafeChars should handle non strings', t => {
const array = ['hello', 'world'];
t.equal(StringUtil.replaceUnsafeChars(array), String(array));
const arrayWithSpecialChar = ['hello', '<world>'];
t.equal(StringUtil.replaceUnsafeChars(arrayWithSpecialChar), 'hello,ltworldgt');
const arrayWithNumbers = [1, 2, 3];
t.equal(StringUtil.replaceUnsafeChars(arrayWithNumbers), '1,2,3');
// Objects shouldn't get provided to replaceUnsafeChars, but in the event
// they do, it should just return the object (and log an error)
const object = {hello: 'world'};
t.equal(StringUtil.replaceUnsafeChars(object), object);
t.end();
});