diff --git a/src/wsdl/index.ts b/src/wsdl/index.ts index 48b182f32..e4e15b7fc 100644 --- a/src/wsdl/index.ts +++ b/src/wsdl/index.ts @@ -23,11 +23,8 @@ const debug = debugBuilder('node-soap'); const XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance'; -const trimLeft = /^[\s\xA0]+/; -const trimRight = /[\s\xA0]+$/; - -function trim(text) { - return text.replace(trimLeft, '').replace(trimRight, ''); +export function trim(text) { + return text.trim(); } function deepMerge(destination: A, source: B): A & B { diff --git a/test/trim-test.js b/test/trim-test.js new file mode 100644 index 000000000..6c5f4103e --- /dev/null +++ b/test/trim-test.js @@ -0,0 +1,30 @@ +trim = require('../lib/wsdl/index.js').trim +var assert = require('assert'); + +it('should trim correctly', async () => { + describe('removes whitespace', async () => { + const input = ' \n <> \n '; + const expected = '<>'; + + verify(input, expected); + }) + + describe('removes non breaking space', async () => { + const input = '\xA0<>'; + const expected = '<>'; + + verify(input, expected); + }); + + describe('removes all', async () => { + const input = '\xA0\n \t<\n\t\xA0>\t \n \xA0'; + const expected = '<\n\t\xA0>'; + + verify(input, expected); + }); +}) + +function verify(input, expected) { + const actual = trim(input); + assert(actual === expected, `${actual} != ${expected}`); +}