Skip to content
Merged
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
22 changes: 14 additions & 8 deletions assets/src/js/learndash/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@
/**
* Decode the HTML entities LearnDash may leave in the saved Video URL.
*
* Only the entities WordPress escaping produces are decoded, by plain string
* replacement, so the value is never reinterpreted as HTML. `&` is decoded
* last so an already-escaped ampersand (`<`) is not decoded twice.
*
* @since n.e.x.t
*
* @param {string} value Field value.
* @param {Document} doc Document.
* @param {string} value Field value.
* @return {string} Decoded value.
*/
const decode = ( value, doc ) => {
const textarea = doc.createElement( 'textarea' );
textarea.innerHTML = value;
return textarea.value;
};
const decode = ( value ) =>
String( value )
.replace( /&lt;/g, '<' )
.replace( /&gt;/g, '>' )
.replace( /&quot;/g, '"' )
.replace( /&#0*39;/g, "'" )
.replace( /&#x0*27;/gi, "'" )
.replace( /&amp;/g, '&' );

/**
* Whether a Video URL value is the GoDAM marker, with or without a picked video.
Expand Down Expand Up @@ -71,7 +77,7 @@ export function setupUseGoDAMSwitch( doc, config ) {
pickerRow.style.display = toggle.checked ? '' : 'none';
}

if ( ! toggle.checked && urlInput && isMarker( decode( urlInput.value, doc ), config.markerTag ) ) {
if ( ! toggle.checked && urlInput && isMarker( decode( urlInput.value ), config.markerTag ) ) {
urlInput.value = '';
}
};
Expand Down
Loading