Skip to content

Commit

Permalink
Change sanitize function to properly handle null values (#4417)
Browse files Browse the repository at this point in the history
* Change sanitize function to properly handle null values

* Update test
  • Loading branch information
jonatanschroeder committed Jun 25, 2021
1 parent 350e1cf commit 27e279f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion prairielib/lib/util.js
Expand Up @@ -6,7 +6,9 @@
* @return {Object} The sanitized object.
*/
module.exports.sanitizeObject = function sanitizeObject(value) {
if (Array.isArray(value)) {
if (value === null) {
return null;
} else if (Array.isArray(value)) {
return value.map(sanitizeObject);
} else if (typeof value === 'string') {
return value.replace('\u0000', '\\u0000');
Expand Down
12 changes: 12 additions & 0 deletions prairielib/lib/util.test.js
Expand Up @@ -69,4 +69,16 @@ describe('sanitizeObject', () => {
};
check(input, expected);
});

test('handles null values correctly', () => {
const input = {
test: 'test\u0000ing',
a: null,
};
const expected = {
test: 'test\\u0000ing',
a: null,
};
check(input, expected);
});
});

0 comments on commit 27e279f

Please sign in to comment.