Skip to content

Commit 0f90f84

Browse files
committed
Merge branch 't/9995b'
2 parents 5097130 + 07ffddd commit 0f90f84

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

core/htmldataprocessor.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,19 @@
4242
// it up and apply the filter.
4343
data = protectSource( data, editor );
4444

45+
// Protect content of textareas. (#9995)
46+
// Do this before protecting attributes to avoid breaking:
47+
// <textarea><img src="..." /></textarea>
48+
data = protectElements( data, protectTextareaRegex );
49+
4550
// Before anything, we must protect the URL attributes as the
4651
// browser may changing them when setting the innerHTML later in
4752
// the code.
4853
data = protectAttributes( data );
4954

5055
// Protect elements than can't be set inside a DIV. E.g. IE removes
5156
// style tags from innerHTML. (#3710)
52-
data = protectElements( data );
57+
data = protectElements( data, protectElementsRegex );
5358

5459
// Certain elements has problem to go through DOM operation, protect
5560
// them by prefixing 'cke' namespace. (#3591)
@@ -646,7 +651,7 @@
646651
break;
647652
}
648653
}
649-
// Disable form elements editing mode provided by some browers. (#5746)
654+
// Disable form elements editing mode provided by some browsers. (#5746)
650655
for ( var i in { input:1,textarea:1 } ) {
651656
defaultDataFilterRules.elements[ i ] = protectReadOnly;
652657
defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly;
@@ -655,7 +660,9 @@
655660
var protectElementRegex = /<(a|area|img|input|source)\b([^>]*)>/gi,
656661
protectAttributeRegex = /\b(on\w+|href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi;
657662

658-
var protectElementsRegex = /(?:<style(?=[ >])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,
663+
// Note: we use lazy star '*?' to prevent eating everything up to the last occurrence of </style> or </textarea>.
664+
var protectElementsRegex = /(?:<style(?=[ >])[^>]*>[\s\S]*?<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,
665+
protectTextareaRegex = /(<textarea(?=[ >])[^>]*>)([\s\S]*?)(?:<\/textarea>)/gi,
659666
encodedElementsRegex = /<cke:encoded>([^<]*)<\/cke:encoded>/gi;
660667

661668
var protectElementNamesRegex = /(<\/?)((?:object|embed|param|html|body|head|title)[^>]*>)/gi,
@@ -676,8 +683,13 @@
676683
});
677684
}
678685

679-
function protectElements( html ) {
680-
return html.replace( protectElementsRegex, function( match ) {
686+
function protectElements( html, regex ) {
687+
return html.replace( regex, function( match, tag, content ) {
688+
// Encode < and > in textarea because this won't be done by a browser, since
689+
// textarea will be protected during passing data through fix bin.
690+
if ( match.indexOf( '<textarea' ) == 0 )
691+
match = tag + unprotectRealComments( content ).replace( /</g, '&lt;' ).replace( />/g, '&gt;' ) + '</textarea>';
692+
681693
return '<cke:encoded>' + encodeURIComponent( match ) + '</cke:encoded>';
682694
});
683695
}

0 commit comments

Comments
 (0)