Ticket #4475: 4475_2.patch

File 4475_2.patch, 3.8 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/wysiwygarea/plugin.js

     
    902902                                                        loadData : function( data )
    903903                                                        {
    904904                                                                isLoadingData = true;
     905                                                                editor._.dataStore = { id : 1 };
    905906
    906907                                                                var config = editor.config,
    907908                                                                        fullPage = config.fullPage,
  • _source/plugins/htmldataprocessor/plugin.js

     
    238238                                        // Remove all class names starting with "cke_".
    239239                                        return CKEDITOR.tools.ltrim( value.replace( /(?:^|\s+)cke_[^\s]*/g, '' ) ) || false;
    240240                                }
    241                         },
    242 
    243                         comment : function( contents )
    244                         {
    245                                 // If this is a comment for protected source.
    246                                 if ( contents.substr( 0, protectedSourceMarker.length ) == protectedSourceMarker )
    247                                 {
    248                                         // Remove the extra marker for real comments from it.
    249                                         if ( contents.substr( protectedSourceMarker.length, 3 ) == '{C}' )
    250                                                 contents = contents.substr( protectedSourceMarker.length + 3 );
    251                                         else
    252                                                 contents = contents.substr( protectedSourceMarker.length );
    253 
    254                                         return new CKEDITOR.htmlParser.cdata( decodeURIComponent( contents ) );
    255                                 }
    256 
    257                                 return contents;
    258                         }
     241                        }
    259242                };
    260243
    261244        if ( CKEDITOR.env.ie )
     
    379362                        });
    380363        }
    381364
    382         function protectSource( data, protectRegexes )
     365        function unprotectSource( html, editor )
    383366        {
     367                var store = editor._.dataStore;
     368                return html.replace( /<!--\{cke_protected\}([\s\S]+?)-->/g, function( match, data )
     369                        {
     370                                return decodeURIComponent( data );
     371                        }).replace( /\{cke_protected_(\d+)\}/g, function( match, id )
     372                        {
     373                                return store[ id ];
     374                        });
     375        }
     376
     377        function protectSource( data, editor )
     378        {
    384379                var protectedHtml = [],
     380                        protectRegexes = editor.config.protectedSource,
     381                        store = editor._.dataStore,
    385382                        tempRegex = /<\!--\{cke_temp(comment)?\}(\d*?)-->/g;
    386383
    387384                var regexes =
     
    414411                                                        return protectedHtml[ id ];
    415412                                                }
    416413                                        );
    417                                         return  '<!--{cke_temp}' + ( protectedHtml.push( match ) - 1 ) + '-->';
     414
     415                                        // Avoid protecting over protected, e.g. /\{.*?\}/
     416                                        return /cke_temp(comment)?/.test( match ) ? match
     417                                                : '<!--{cke_temp}' + ( protectedHtml.push( match ) - 1 ) + '-->';
    418418                                });
    419419                }
    420420                data = data.replace( tempRegex, function( $, isComment, id )
     
    425425                                                '-->';
    426426                        }
    427427                );
    428                 return data;
     428
     429                // Different protection pattern is used for those that
     430                // live in attributes to avoid from being HTML encoded.
     431                return data.replace( /(['"]).*?\1/g, function ( match )
     432                {
     433                        return match.replace( /<!--\{cke_protected\}([\s\S]+?)-->/g, function( match, data )
     434                        {
     435                                store[ store.id ] = decodeURIComponent( data );
     436                                return '{cke_protected_'+ store.id++  + '}';
     437                        })
     438                });
    429439        }
    430440
    431441        CKEDITOR.plugins.add( 'htmldataprocessor',
     
    471481                        // The source data is already HTML, but we need to clean
    472482                        // it up and apply the filter.
    473483
    474                         data = protectSource( data, this.editor.config.protectedSource );
     484                        data = protectSource( data, this.editor );
    475485
    476486                        // Before anything, we must protect the URL attributes as the
    477487                        // browser may changing them when setting the innerHTML later in
     
    533543
    534544                        fragment.writeHtml( writer, this.htmlFilter );
    535545
    536                         return writer.getHtml( true );
     546                        var data = writer.getHtml( true );
     547
     548                        // Restore those non-HTML protected source. (#4475,#4880)
     549                        data = unprotectRealComments( data );
     550                        data = unprotectSource( data, this.editor );
     551
     552                        return data;
    537553                }
    538554        };
    539555})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy