Skip to content

Commit 493f477

Browse files
committed
Merge branch 't/10076' into major
2 parents db6ffc3 + 1509c36 commit 493f477

File tree

1 file changed

+62
-54
lines changed

1 file changed

+62
-54
lines changed

core/filter.js

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@
104104
this.applyTo( evt.data.dataValue, true );
105105
}, this, null, 6 );
106106

107-
// Filter outcoming "data".
108-
// Add element filter after htmlDataProcessor.htmlFilter
107+
// Transform outcoming "data".
108+
// Add element filter after htmlDataProcessor.htmlFilter
109109
// when preparing output data HTML.
110110
this._.toDataFormatListener = editor.on( 'toDataFormat', function( evt ) {
111-
this.applyTo( evt.data.dataValue );
111+
this.applyTo( evt.data.dataValue, false, true );
112112
}, this, null, 11 );
113113
}
114114
// Rules object passed in editorOrRules argument - initialize standalone filter.
@@ -192,11 +192,13 @@
192192
* of filtering is DOM tree without disallowed content.
193193
*
194194
* @param {CKEDITOR.htmlParser.fragment/CKEDITOR.htmlParser.element} fragment Node to be filtered.
195-
* @param {Boolean} toHtml Set to `true` if filter is used together with {@link CKEDITOR.htmlDataProcessor#toHtml}.
195+
* @param {Boolean} [toHtml] Set to `true` if filter is used together with {@link CKEDITOR.htmlDataProcessor#toHtml}.
196+
* @param {Boolean} [transformOnly] If set to `true` only transformations will be applied. Content
197+
* won't be filtered with allowed content rules.
196198
*/
197-
applyTo: function( fragment, toHtml ) {
199+
applyTo: function( fragment, toHtml, transformOnly ) {
198200
var toBeRemoved = [],
199-
rules = this._.rules,
201+
rules = !transformOnly && this._.rules,
200202
transformations = this._.transformations,
201203
filterFn = getFilterFunction( this ),
202204
protectedRegexs = this.editor && this.editor.config.protectedSource;
@@ -717,7 +719,7 @@
717719

718720
// Return and cache created function.
719721
// @param {CKEDITOR.htmlParser.element}
720-
// @param optimizedRules Rules to be used.
722+
// @param [optimizedRules] Rules to be used.
721723
// @param [transformations] Transformations to be applied.
722724
// @param {Array} toBeRemoved Array into which elements rejected by the filter will be pushed.
723725
// @param {Boolean} [toHtml] Set to true if filter used together with htmlDP#toHtml
@@ -739,61 +741,67 @@
739741

740742
for ( i = 0; i < transformations.length; ++i )
741743
applyTransformationsGroup( that, element, transformations[ i ] );
742-
}
743-
744-
// Name could be changed by transformations.
745-
name = element.name;
746-
747-
var rules = optimizedRules.elements[ name ],
748-
genericRules = optimizedRules.generic,
749-
status = {
750-
// Whether any of rules accepted element.
751-
// If not - it will be stripped.
752-
valid: false,
753-
// Objects containing accepted attributes, classes and styles.
754-
validAttributes: {},
755-
validClasses: {},
756-
validStyles: {},
757-
// Whether all are valid.
758-
// If we know that all element's attrs/classes/styles are valid
759-
// we can skip their validation, to improve performance.
760-
allAttributes: false,
761-
allClasses: false,
762-
allStyles: false
763-
};
764744

765-
// Early return - if there are no rules for this element (specific or generic), remove it.
766-
if ( !rules && !genericRules ) {
767-
toBeRemoved.push( element );
768-
return;
745+
// Update style and class attrs, because that won't be done after applying rules.
746+
if ( !optimizedRules )
747+
updateAttributes( element );
769748
}
770749

771-
// Could not be done yet if there were no transformations and if this
772-
// is real (not mocked) object.
773-
populateProperties( element );
750+
if ( optimizedRules ) {
751+
// Name could be changed by transformations.
752+
name = element.name;
753+
754+
var rules = optimizedRules.elements[ name ],
755+
genericRules = optimizedRules.generic,
756+
status = {
757+
// Whether any of rules accepted element.
758+
// If not - it will be stripped.
759+
valid: false,
760+
// Objects containing accepted attributes, classes and styles.
761+
validAttributes: {},
762+
validClasses: {},
763+
validStyles: {},
764+
// Whether all are valid.
765+
// If we know that all element's attrs/classes/styles are valid
766+
// we can skip their validation, to improve performance.
767+
allAttributes: false,
768+
allClasses: false,
769+
allStyles: false
770+
};
771+
772+
// Early return - if there are no rules for this element (specific or generic), remove it.
773+
if ( !rules && !genericRules ) {
774+
toBeRemoved.push( element );
775+
return;
776+
}
774777

775-
if ( rules ) {
776-
for ( i = 0, l = rules.length; i < l; ++i )
777-
applyRule( rules[ i ], element, status, true, skipRequired );
778-
}
778+
// Could not be done yet if there were no transformations and if this
779+
// is real (not mocked) object.
780+
populateProperties( element );
779781

780-
if ( genericRules ) {
781-
for ( i = 0, l = genericRules.length; i < l; ++i )
782-
applyRule( genericRules[ i ], element, status, false, skipRequired );
783-
}
782+
if ( rules ) {
783+
for ( i = 0, l = rules.length; i < l; ++i )
784+
applyRule( rules[ i ], element, status, true, skipRequired );
785+
}
784786

785-
// Finally, if after running all filter rules it still hasn't been allowed - remove it.
786-
if ( !status.valid ) {
787-
toBeRemoved.push( element );
788-
return;
789-
}
787+
if ( genericRules ) {
788+
for ( i = 0, l = genericRules.length; i < l; ++i )
789+
applyRule( genericRules[ i ], element, status, false, skipRequired );
790+
}
790791

791-
// Update element's attributes based on status of filtering.
792-
updateElement( element, status );
792+
// Finally, if after running all filter rules it still hasn't been allowed - remove it.
793+
if ( !status.valid ) {
794+
toBeRemoved.push( element );
795+
return;
796+
}
793797

794-
if ( !skipFinalValidation && !validateElement( element ) ) {
795-
toBeRemoved.push( element );
796-
return;
798+
// Update element's attributes based on status of filtering.
799+
updateElement( element, status );
800+
801+
if ( !skipFinalValidation && !validateElement( element ) ) {
802+
toBeRemoved.push( element );
803+
return;
804+
}
797805
}
798806

799807
// Protect previously unprotected elements.

0 commit comments

Comments
 (0)