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 #140 from ckeditor/t/139
Browse files Browse the repository at this point in the history
Fix: `<a>` elements without the `href` attribute should not be picked up by the converter when loading data or pasting. Closes #139.
  • Loading branch information
oleq authored Jul 14, 2017
2 parents fe0981c + b73206b commit 80e4c03
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/linkengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default class LinkEngine extends Plugin {

// Build converter from view to model for data pipeline.
buildViewConverter().for( data.viewToModel )
.fromElement( 'a' )
// Convert <a> with href (value doesn't matter).
.from( { name: 'a', attribute: { href: /.?/ } } )
.toAttribute( viewElement => ( {
key: 'linkHref',
value: viewElement.getAttribute( 'href' )
Expand Down
18 changes: 18 additions & 0 deletions tests/linkengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ describe( 'LinkEngine', () => {

expect( editor.getData() ).to.equal( '<p>foobar</p>' );
} );

// https://github.com/ckeditor/ckeditor5/issues/500
it( 'should not pick up `<a name="foo">`', () => {
editor.setData( '<p><a name="foo">foo</a>bar</p>' );

expect( getModelData( doc, { withoutSelection: true } ) )
.to.equal( '<paragraph>foobar</paragraph>' );
} );

// CKEditor 4 does. And CKEditor 5's balloon allows creating such links.
it( 'should pick up `<a href="">`', () => {
editor.setData( '<p><a href="">foo</a>bar</p>' );

expect( getModelData( doc, { withoutSelection: true } ) )
.to.equal( '<paragraph><$text linkHref="">foo</$text>bar</paragraph>' );

expect( editor.getData() ).to.equal( '<p><a href="">foo</a>bar</p>' );
} );
} );

describe( 'editing pipeline conversion', () => {
Expand Down

0 comments on commit 80e4c03

Please sign in to comment.