ソースを参照

Merge pull request #140 from ckeditor/t/139

Fix: `<a>` elements without the `href` attribute should not be picked up by the converter when loading data or pasting. Closes #139.
Aleksander Nowodzinski 8 年 前
コミット
fa98cd7b0a

+ 2 - 1
packages/ckeditor5-link/src/linkengine.js

@@ -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' )

+ 18 - 0
packages/ckeditor5-link/tests/linkengine.js

@@ -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', () => {