Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #944 from ckeditor/t/943
Browse files Browse the repository at this point in the history
Fix: `MarkerDelta` transformation should no longer cause editor to crash, if a `MarkerOperation` had `null` as it's `oldRange` or `newRange`. Closes #943.
  • Loading branch information
Reinmar authored May 11, 2017
2 parents 6875eff + 50d0c09 commit d328811
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/model/delta/basic-transformations.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ function transformMarkerDelta( a, b ) {
const transformedDelta = a.clone();
const transformedOp = transformedDelta.operations[ 0 ];

transformedOp.oldRange = transformedOp.oldRange.getTransformedByDelta( b )[ 0 ];
transformedOp.newRange = transformedOp.newRange.getTransformedByDelta( b )[ 0 ];
if ( transformedOp.oldRange ) {
transformedOp.oldRange = transformedOp.oldRange.getTransformedByDelta( b )[ 0 ];
}

if ( transformedOp.newRange ) {
transformedOp.newRange = transformedOp.newRange.getTransformedByDelta( b )[ 0 ];
}

return [ transformedDelta ];
}
Expand Down
21 changes: 21 additions & 0 deletions tests/model/delta/transform/markerdelta.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,25 @@ describe( 'transform', () => {
} );
} );
} );

it( 'null ranges of MarkerDelta should not be changed during transformation', () => {
const markerDelta = getMarkerDelta( 'name', null, null, baseVersion );

// Transform `markerDelta` by any other delta that has a special transformation case with `MarkerDelta`.
const wrapElement = new Element( 'w' );
const wrapRange = new Range( new Position( root, [ 1 ] ), new Position( root, [ 2 ] ) );
const wrapDelta = getWrapDelta( wrapRange, wrapElement, baseVersion );

const transformed = transform( markerDelta, wrapDelta );

expect( transformed.length ).to.equal( 1 );
expect( transformed[ 0 ].operations.length ).to.equal( 1 );

const transformedOp = transformed[ 0 ].operations[ 0 ];

expect( transformedOp ).to.be.instanceof( MarkerOperation );
expect( transformedOp.oldRange ).to.be.null;
expect( transformedOp.newRange ).to.be.null;
expect( transformedOp.name ).to.equal( 'name' );
} );
} );

0 comments on commit d328811

Please sign in to comment.