Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 7aa55ba

Browse files
committed
fix serializing html with embed codes containing scripts
1 parent 03c7219 commit 7aa55ba

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/js/core.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@
136136

137137
$data.find('.medium-insert-buttons').remove();
138138

139+
// Restore original embed code from embed wrapper attribute value.
140+
$data.find('[data-embed-code]').each(function() {
141+
var $this = $(this);
142+
$this.html($this.attr('data-embed-code'));
143+
});
144+
139145
data[key].value = $data.html();
140146
});
141147

src/js/embeds.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,25 @@
298298
success: function(data) {
299299
var html = data && data.html;
300300

301-
if (data && !data.html && data.type === 'photo' && data.url) {
301+
if (data && !html && data.type === 'photo' && data.url) {
302302
html = '<img src="' + data.url + '" alt="">';
303303
}
304304

305+
if (!html) {
306+
// Prevent render empty embed.
307+
$.proxy(that, 'convertBadEmbed', url)();
308+
return;
309+
}
310+
311+
if (html && html.indexOf('</script>') > -1) {
312+
// Store embed code with <script> tag inside wrapper attribute value.
313+
// Make nice attribute value escaping using jQuery.
314+
var $div = $('<div>')
315+
.attr('data-embed-code', html)
316+
.html(html);
317+
html = $('<div>').append($div).html();
318+
}
319+
305320
$.proxy(that, 'embed', html)();
306321
},
307322
error: function(jqXHR, textStatus, errorThrown) {

0 commit comments

Comments
 (0)