Skip to content

Commit

Permalink
Merge pull request #1216 from shellicar/fix/trim-speed
Browse files Browse the repository at this point in the history
Improve trim speed during XML parsing
  • Loading branch information
w666 authored Apr 18, 2024
2 parents de9dd25 + 499395a commit 690ae8c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<A, B>(destination: A, source: B): A & B {
Expand Down
30 changes: 30 additions & 0 deletions test/trim-test.js
Original file line number Diff line number Diff line change
@@ -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}`);
}

0 comments on commit 690ae8c

Please sign in to comment.