Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit 2c8d52a

Browse files
Valerii RadkolukaszMycs
authored andcommitted
Update nlapiEscapeXML function (#17)
* Update nlapiEscapeXML function * Add test for nlapiEscapeXML function * Update test for nlapiEscapeXML function
1 parent e34f601 commit 2c8d52a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

SuiteScriptMockup1.0/nsmockup-1.0.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,13 @@ exports.nlapiEncrypt = function (s) { };
13771377
*
13781378
* @since 2008.1
13791379
*/
1380-
exports.nlapiEscapeXML = function (text) { encodeURI(text); };
1380+
exports.nlapiEscapeXML = function (input) {
1381+
return input.replace(/&/g, '\\&')
1382+
.replace(/</g, '\\<')
1383+
.replace(/>/g, '\\>')
1384+
.replace(/"/g, '\\"')
1385+
.replace(/'/g, "\\'");
1386+
};
13811387

13821388
/**
13831389
* Convert a String into an XML document. Note that in Server SuiteScript XML is supported natively by the JS runtime using the e4x standard (http://en.wikipedia.org/wiki/E4X)
@@ -3429,7 +3435,7 @@ exports.nlobjFile.prototype.getValue = function () { };
34293435
*
34303436
* @since 2007.0
34313437
*/
3432-
exports.nlobjSearchFilter = require('../Utils/search-filter');
3438+
exports.nlobjSearchFilter = require('../Utils/search-filter');
34333439

34343440
/**
34353441
* Return the name of this search filter.

Tests/SuiteScriptMockup1.0/nsmockup-1.0.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ describe('Testing nsmockup-1.0 library', () => {
3131
expect(fileUnderTest.nlapiLookupField()).toEqual(expect.any(String));
3232
});
3333
});
34-
34+
describe('nlapiEscapeXML', () => {
35+
it('Should return a string', () => {
36+
const xml = '<?xml version="1.0" encoding="UTF-8"?>';
37+
const escappedXml = '\\<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?\\>';
38+
const result = fileUnderTest.nlapiEscapeXML(xml);
39+
expect(result).toBe(escappedXml);
40+
});
41+
});
3542
describe('nlobjError', () => {
3643
it('Should create nlobjError object', () => {
3744
// eslint-disable-next-line new-cap

0 commit comments

Comments
 (0)