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
17 changes: 17 additions & 0 deletions src/lightbox/frontend-image-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ const isImageBlock = el => {
return el && el.classList.contains( 'stk-block-image' )
}

function sanitize( string ) {
const map = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
'/': '&#x2F;',
}
const reg = /[&<>"'/]/ig
return string.replace( reg, match => map[ match ] )
}

class StackableImageLightbox {
init = () => {
this.elements = []
Expand Down Expand Up @@ -135,6 +148,10 @@ class StackableImageLightbox {
title = imageBlock.getAttribute( 'alt' ) || null
}

// Sanitize strings.
title = title ? sanitize( title ) : null
link = typeof link === 'string' ? sanitize( link ) : link

const isUsingImageBlock = ( ! link || ! href ) && imageBlock

this.elements.push( {
Expand Down
Loading