Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve trim speed during XML parsing. #1216

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`);
}