Skip to content

Commit

Permalink
Merge pull request #542 from wpmudev/fix/SUI-570
Browse files Browse the repository at this point in the history
🐛 fix(select2): escape script tags in select2 options.
  • Loading branch information
rtbfreitas authored Jun 9, 2023
2 parents 731e0c1 + 5b0c556 commit b357ef3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions assets/js/shared-ui/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@

SUI.select = {};

SUI.select.escapeJS = ( string ) => {

// Create a temporary <div> element using jQuery and set the HTML content.
var div = $( '<div>' ).html( string );

// Get the text content of the <div> element and remove script tags
var text = div.text().replace( /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '' );

// Return the escaped text
return text;
};

SUI.select.formatIcon = ( data, container ) => {

let markup;

const label = data.text;
const label = SUI.select.escapeJS( data.text );
const icon = $( data.element ).attr( 'data-icon' );

if ( ! data.id ) {
Expand All @@ -32,7 +44,7 @@

let markup;

const label = data.text;
const label = SUI.select.escapeJS( data.text );
const icon = $( data.element ).attr( 'data-icon' );

if ( 'undefined' !== typeof icon ) {
Expand All @@ -49,7 +61,7 @@

let markup, border;

const label = data.text;
const label = SUI.select.escapeJS( data.text );
const color = $( data.element ).attr( 'data-color' );

if ( ! data.id ) {
Expand Down Expand Up @@ -90,7 +102,7 @@

let markup;

const label = data.text;
const label = SUI.select.escapeJS( data.text );
const color = $( data.element ).attr( 'data-color' );

if ( 'undefined' !== typeof color ) {
Expand Down Expand Up @@ -127,7 +139,7 @@

let markup;

const label = data.text;
const label = SUI.select.escapeJS( data.text );
const content = $( data.element ).val();

if ( ! data.id ) {
Expand All @@ -148,7 +160,7 @@

let markup;

const label = data.text;
const label = SUI.select.escapeJS( data.text );

markup = '<span class="sui-icon-plus-circle sui-md" aria-hidden="true"></span>';
markup += '<span class="sui-screen-reader-text">' + label + '</span>';
Expand Down

0 comments on commit b357ef3

Please sign in to comment.