Opened 4 years ago

Closed 2 years ago

#14603 closed Bug (fixed)

Function "contains " in elementpath don't exclude root element if it is search from top

Reported by: Ben Ng Owned by:
Priority: Normal Milestone:
Component: General Version: 4.0
Keywords: Cc:

Description

Steps to reproduce

  1. Call the contains function of a elementpath with excludeRoot and fromTop are both TRUE

Expected result

The root element should be excluded.

Actual result

The deepest element is excluded. It is because the elements array is reversed when fromTop is true. The root element is moved to the first element of the array instead of the last one. The for loop exclude the last element if excludeRoot is true.

Change History (3)

comment:1 Changed 4 years ago by Jakub Ś

Keywords: elementpath contains removed
Status: newconfirmed
Version: 4.5.9 (GitHub - master)4.0

Problem can be reproduced at least from CKEditor 4.0.

  1. Start editor with below content and code
    HTML page:
    <div id="test1">					
        test text					
    </div>
    
    JS Code:
    var editor = CKEDITOR.replace( 'editor1', {});
    editor.on( "instanceReady", function( event ) {
    	var rootEl = editor.document.getById('test1');
    	var elPath = new CKEDITOR.dom.elementPath( rootEl, rootEl.getParent() );			
    	console.log( elPath.contains( 'body', true, true ) );
    });
    

Result: According to documentation root elopement should be excluded and null should be logged. Instead body element is found.

comment:2 Changed 2 years ago by Marek Lewandowski

Faced the same issue, reported in to the GitHub in https://github.com/ckeditor/ckeditor-dev/issues/684 so it can be tracked there.

comment:3 Changed 2 years ago by kkrzton

Resolution: fixed
Status: confirmedclosed
Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy