// Licensed to Cloudera, Inc. under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Cloudera, Inc. licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import deXSS from './deXSS';
describe('deXSS.ts', () => {
it('should return empty string when the value is undefined', () => {
expect(deXSS(undefined)).toEqual('');
});
it('should return false when the value is false', () => {
expect(deXSS(false)).toEqual('false');
});
it('should return 0 when the value is 0', () => {
expect(deXSS(0)).toEqual('0');
});
it('should return null when the value is null', () => {
expect(deXSS(null)).toEqual('null');
});
it('should remove JS code from a string', () => {
expect(deXSS('hello world')).toEqual('hello world');
});
it('Should not remove strong tag from a string', () => {
expect(deXSS('Hello World')).toEqual('Hello World');
});
it('Should remove img tag from a string', () => {
expect(deXSS('hello')).toEqual('hello');
});
it('Should not remove p tag from a string', () => {
expect(deXSS('
Hello World
')).toEqual('Hello World
'); }); it('Should not remove h1 tag from a string', () => { expect(deXSS('Whee
')).toEqual('Whee
'); }); it('should dump an uppercase javascript url', () => { expect(deXSS('Hax')).toEqual('Hax'); }); it('should return a comma-separated string for an array', () => { expect(deXSS([1, 2, 3])).toEqual('1,2,3'); }); it('should return JSON string for an object', () => { expect(deXSS({ key: 'value' })).toEqual('{"key":"value"}'); }); it('should return JSON string for a map', () => { const map = new Map(); map.set('key', 'value'); expect(deXSS(Object.fromEntries(map))).toEqual('{"key":"value"}'); }); it('should return JSON string for a nested object', () => { const nestedObject = { key1: 'value1', key2: { nestedKey: 'nestedValue' } }; expect(deXSS(nestedObject)).toEqual('{"key1":"value1","key2":{"nestedKey":"nestedValue"}}'); }); it('should return JSON string for a complex map', () => { const map = new Map(); map.set('struct', { array1: [1, 2, 3], array2: ['a', 'b', 'c'] }); expect(deXSS(Object.fromEntries(map))).toEqual( '{"struct":{"array1":[1,2,3],"array2":["a","b","c"]}}' ); }); });