Cherry pick PR#50802 into trunk (#50811)
This commit is contained in:
parent
28ce18e13a
commit
749adf304d
|
@ -102,4 +102,20 @@ describe( 'currency.formatDecimalString', () => {
|
||||||
// @ts-expect-error formatAccount expects a number or string;
|
// @ts-expect-error formatAccount expects a number or string;
|
||||||
expect( currency.formatDecimalString( null ) ).toBe( '' );
|
expect( currency.formatDecimalString( null ) ).toBe( '' );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
it( 'should strip tags in getPriceFormat', () => {
|
||||||
|
const currency = Currency();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
currency.getPriceFormat( {
|
||||||
|
priceFormat: '<b>tag</b>format',
|
||||||
|
} )
|
||||||
|
).toBe( 'tagformat' );
|
||||||
|
|
||||||
|
expect(
|
||||||
|
currency.getPriceFormat( {
|
||||||
|
priceFormat: '<script>tag</script>format',
|
||||||
|
} )
|
||||||
|
).toBe( 'format' );
|
||||||
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -66,9 +66,17 @@ const CurrencyFactoryBase = function ( currencySetting?: CurrencyConfig ) {
|
||||||
let currency: Currency;
|
let currency: Currency;
|
||||||
|
|
||||||
function stripTags( str: string ) {
|
function stripTags( str: string ) {
|
||||||
const tmp = document.createElement( 'DIV' );
|
// sanitize Polyfill - see https://github.com/WordPress/WordPress/blob/master/wp-includes/js/wp-sanitize.js
|
||||||
tmp.innerHTML = str;
|
const strippedStr = str
|
||||||
return tmp.textContent || tmp.innerText || '';
|
.replace( /<!--[\s\S]*?(-->|$)/g, '' )
|
||||||
|
.replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/gi, '' )
|
||||||
|
.replace( /<\/?[a-z][\s\S]*?(>|$)/gi, '' );
|
||||||
|
|
||||||
|
if ( strippedStr !== str ) {
|
||||||
|
return stripTags( strippedStr );
|
||||||
|
}
|
||||||
|
|
||||||
|
return strippedStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue