Ticket #1717: infinite_loop_avoidance.patch

File infinite_loop_avoidance.patch, 2.4 KB (added by Martin Kou, 16 years ago)

Patch for avoiding infinite loops in FCKDomRangeIterator. This is NOT intended to be the final fix to #1717.

  • editor/_source/classes/fckdomrangeiterator.js

     
    258258                                // block.
    259259                                if ( !range.CheckStartOfBlock() || !range.CheckEndOfBlock() )
    260260                                {
    261                                         // The resulting block will be a clone of the current one.
    262                                         block = block.cloneNode( false ) ;
     261                                        // Extract the range contents, move it to a new block if the extracted contents aren't empty.
     262                                        var contentsFragment = range.ExtractContents() ;
    263263
    264                                         // Extract the range contents, moving it to the new block.
    265                                         range.ExtractContents().AppendTo( block ) ;
    266                                         FCKDomTools.TrimNode( block ) ;
     264                                        // Examine the extracted contents, see if there's any visible content in it.
     265                                        var contentsRoot = contentsFragment.RootNode ;
     266                                        var editStartNode = contentsRoot, editEndNode = contentsRoot, child ;
     267                                        while ( ( child = editStartNode.firstChild ) && child.nodeType == 1 &&
     268                                                        FCKListsLib.InlineNonEmptyElements[ child.nodeName.toLowerCase() ] )
     269                                                editStartNode = child ;
     270                                        while ( ( child = editEndNode.firstChild ) && child.nodeType == 1 &&
     271                                                        FCKListsLib.InlineNonEmptyElements[ child.nodeName.toLowerCase() ] )
     272                                                editEndNode = child ;
    267273
    268                                         // Split the block. At this point, the range will be in the
    269                                         // right position for our intents.
    270                                         var splitInfo = range.SplitBlock() ;
     274                                        // Check if the extracted contents if visibly empty by checking if there's any editable
     275                                        // contents.
     276                                        if ( editStartNode != editEndNode || editStartNode.firstChild )
     277                                        {
     278                                                // The resulting block will be a clone of the current one.
     279                                                block = block.cloneNode( false ) ;
    271280
    272                                         removePreviousBr = !splitInfo.WasStartOfBlock ;
    273                                         removeLastBr = !splitInfo.WasEndOfBlock ;
     281                                                contentsFragment.AppendTo( block ) ;
     282                                                FCKDomTools.TrimNode( block ) ;
    274283
    275                                         // Insert the new block into the DOM.
    276                                         range.InsertNode( block ) ;
     284                                                // Split the block. At this point, the range will be in the
     285                                                // right position for our intents.
     286                                                var splitInfo = range.SplitBlock() ;
     287
     288                                                removePreviousBr = !splitInfo.WasStartOfBlock ;
     289                                                removeLastBr = !splitInfo.WasEndOfBlock ;
     290
     291                                                // Insert the new block into the DOM.
     292                                                range.InsertNode( block ) ;
     293                                        }
    277294                                }
    278295                        }
    279296                        else if ( !isLast )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy